excelvbaisfun
DESCRIPTION
excel vbaTRANSCRIPT
EXCEL VBA BASICS #8 - FIND THE LAST ROW OR COLUMN DYNAMICALLY AND CLEARING OUT YOUR LAST REPORT
1. Lastrow=ThisWorkbook.Sheets (“My Report”).Cells (Rows.Count,1).End(xlUp).Row- Gives last row number
2. Selection.End(xlToLeft).column - Gives last column number. Put cursor in any cell and press ctrl + left. This is the same operation happens with this piece of code and returns the column number
3. ThisWorkbook.Sheets (“My Report”).Range (“a1:c” & Lastrow).ClearContents – Clears cells in the given range
EXCEL VBA BASICS #11 CREATE YOUR OWN CUSTOM FUNCTIONS WITH OR WITHOUT ARGUMENTS
/* Gives the last row number in column one*/Function LastRow() LastRow=activesheet.Cells(rows.count,1).end(xlup).rowEnd Funcion
Now put cursor in any cell and use this function like we use normal built in functions(=LastRow() and hit enter).
/* Gives the last row number of the selected cell’s column */Function LastRowC(SelectedCell As Range)
sc=SelectedCell.Column LastRow=activesheet.Cells(rows.count,sc).end(xlup).row
End Function
Similarly you can use this function as =LastRowC(‘now select any cell’) hit enter.