I have searched this site and it seems like all the answers just point to finding the row number of the cell.
I am trying to set a range so that it will go from
This will give the last row in a given column
= Cells(Activesheet.Rows.Count, ColumnNumber).End(xlUp).Row (Fixed per @Gimp)
you then have a reference you can use to add to the data - e.g if you want to look in column "A", then that would be columnnumber 1. feed that into the function, then you can use Cells(NumberReturnedFromFunction,ColumnNumber) to address that cell, and add .Address if you want the A1 style of address
This will return the range object corresponding to the last filled in cell in column A
Range("A:A").Find("*",Range("A1"),SearchDirection:=xlprevious)
If you want the row number, use the following:
Range("A:A").Find("*",Range("A1"),SearchDirection:=xlprevious).row
Try using something like this:
Activesheet.Cells(Activesheet.Rows.Count, "A").End(xlUp).Row
You can replace Activesheet with references to a sheet's index # like Sheets(1) or the sheet name like Sheets("Sheet1")
By using the Rows.Count it will check to see what the max rows are and be compatible across all versions of Excel.
In the end you can use this within your range reference like this:
Msgbox Sheets(1).Range("A" & Sheets(1).Cells(Sheets(1).Rows.Count, "A").End(xlUp).row).value
But I'd probably rewrite that as
With Sheets(1)
Msgbox .Range("A" & .Cells(.Rows.Count, "A").End(xlUp).row).value
End With
In case there are gaps in the data I'd avoid using xlDown so something like the following is fine. Try it in the immediate window:
Activesheet.range("A1:A" & Activesheet.Cells(Excel.Rows.Count, 1).End(Excel.xlUp).Row).select