ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   goto last cell with data (https://www.excelbanter.com/excel-programming/418664-goto-last-cell-data.html)

W[_2_]

goto last cell with data
 
Hi all,

I export a query from Access on which I have to perform statistical analysis.
The data always start at cell A2, but can stop at whatever cell in the A
range. E.g. it could be A345 or A21.

How can I, programmatically, position myself on A2 and then select from A2
till the last "filled" cell, e.g. A345 ?

Thank you,

W

Gary''s Student

goto last cell with data
 
Sub dural()
n = Cells(Rows.Count, "A").End(xlUp).Row
Range("A2:A" & n).Select
End Sub

--
Gary''s Student - gsnu200808

W[_2_]

goto last cell with data
 
Thank you, this works fine.

W

Charlotte E.[_2_]

goto last cell with data
 
And, in case you don't know, Gary's code can be made into one single line:

Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).Select


And in case, you want to make sure that selection isn't done 'backward', if
no cell with data is found in column A:

Range("A2:A" & WorksheetFunction.Max(2, Cells(Rows.Count,
"A").End(xlUp).Row)).Select


Sorry, Gary :-)

CE



--
Gary''s Student - gsnu200808

Gary''s Student wrote:
Sub dural()
n = Cells(Rows.Count, "A").End(xlUp).Row
Range("A2:A" & n).Select
End Sub





All times are GMT +1. The time now is 01:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com