VBA Basics

Small projects in VBA for Excel and other bits of programming.

VBA Basics

Finding the bottom row used in a column

The following piece of code when run will return the row number of the bottom row to the variable. In this case it will run in column A as in the cells function we have stated column 1 as teh second parameter, this can be changed to any number or a variable.

Public Sub BottomRow()
	LastRow = Cells(Rows.Count, 1).End(xlUp).Row
End Sub

Finding the rightmost column used in a row

The following piece of code when run will return the rightmost column number to the variable. In this case it will run in column 1 as in the cells function we have stated row 1 as the first parameter, this can be changed to any number or a variable.

Public Sub BottomRow()
	LastCol = Cells(1, Columns.Count).End(xltoLeft).Column
End Sub