- Hello Everyone
When we create macro in excel then sometime data range is not fixed or it dyamanic For example, this time we have worked in which 100 rows and 10 columns, but next time it would less or more like less than 100 or more than it.
if we are working with recorded macro and data range fixed then we don't need to get last row and columns.
But if we are using any Loop then we have to find out last row and columns.
sub lastrow()
Dim wkb as workbook
Dim wks as worksheet
Dim LRN as long
Dim LCN as long
Set wkb = Thisworkbook
Set wks = wkb.worksheets("Sheetname")
Below code give you last row number of active sheet
LRN = wks.cells(rows.count,1).end(xlup).rows
Below code give you last col number of active sheet
LCN = wks.cells(1,columns.count).end(xltoleft).columns
End sub
I have you will try this code if your project and let us know if you have any query on it.
0 Comments