I am trying to enter the row number of the last row of data in a worksheet in cell A LASTROW+1 and I keep getting an error. What am I doing wrong?
Dim LastRow As Long
LastRow = Range("A65536").End(xlUp).Row
range("A"lastrow+1).value=lastrow
lastrow?
-
- Administrator
- Posts: 12605
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: lastrow?
Try putting an Ampersand between "A" and lastrow+1 so that it reads
Range("A" & LastRow + 1).Value=LastRow
Range("A" & LastRow + 1).Value=LastRow
StuartR
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: lastrow?
Thanks a lot - perfect! Now I can focus on looping through rows until I reach lastrow. Love this stuff (almost always).
Don
-
- 3StarLounger
- Posts: 392
- Joined: 25 Jan 2010, 12:21
Re: lastrow?
Instead of:
LastRow = Range("A65536").End(xlUp).Row
You may want to change to:
Lastrow = cells(activesheet.rows.count,1).end(xlup).row
Yours will work for versions of XL before XL2007, but may not give the right value for workbooks starting with XL2007 since row 65536 is no longer the last row. The variant is more general and will work with any version since it determines the last row of the worksheet at runtime.
This will prevent issues when you do upgrade and have larger datasets.
Steve
LastRow = Range("A65536").End(xlUp).Row
You may want to change to:
Lastrow = cells(activesheet.rows.count,1).end(xlup).row
Yours will work for versions of XL before XL2007, but may not give the right value for workbooks starting with XL2007 since row 65536 is no longer the last row. The variant is more general and will work with any version since it determines the last row of the worksheet at runtime.
This will prevent issues when you do upgrade and have larger datasets.
Steve
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA