Help with LastRow

  • Thread starter Thread starter JStone0218
  • Start date Start date
J

JStone0218

I need help modifying the following code:

Sub Test()

With ActiveSheet
Range("a" & ActiveCell.Row).Offset(1, 0).Select
End With

End Sub

I have data in column "a" and I need the code above to execute until it reaches
the last row. The range is variable based on the data I import from another
file. Is this doable?

Thanks,

James
 
JStone0218,

I have plagiarized this from J.E. McGimpsey


For Each cell In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)

Do whatever it is you want to do on your column A of data.

Next cell

The For Each statement says in effect,

Start in A1,
Count the number of rows
now xlUP from the bottom (number of rows)

So you have defined the bottom row.

Hope that helps.

Regards,
Kevin
 
Hello James,

'You can use .SELECT instead of Application.Goto
Application.Goto Range("A65536").End(xlUp).Offset(1)
or

Application.Goto Cells(Rows.Count, 1).End(xlUp).Offset(1)

I think it is faster than looping cells.


--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Colo of 'The Road of The Cell Masters' :)

URL:http://www.interq.or.jp/sun/puremis/colo/CellMastersLink.htm
mailto:[email protected]

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
 
Kevin,

Thanks, this worked great!

James

Kevin Stecyk said:
JStone0218,

I have plagiarized this from J.E. McGimpsey


For Each cell In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)

Do whatever it is you want to do on your column A of data.

Next cell

The For Each statement says in effect,

Start in A1,
Count the number of rows
now xlUP from the bottom (number of rows)

So you have defined the bottom row.

Hope that helps.

Regards,
Kevin
 
Back
Top