Step/Loop Macro Help

Learn&Prosper

New Member
Joined
Jan 13, 2012
Messages
32
I am a complete novice at Excel macros and only really record macros.

I just want a simple macro to select sell A1 in say Sheet1 and then if it is empty to Stop and if it not empty to go down one cell (offset down 1 row) to A2 and continue that process until it finds an empty cell (A3, A4, etc)

Please help me.

Thanks.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Code:
With Sheets("Sheet1").
If Len(.Range("A1")) > 0 then
Sheets("Sheet1").Range("A1").End(xlDown).Select
Else
.Range("A1").Select
End If
End With
 
Upvote 0
Ignore previous post - this won't work if A1 contains a value but A2 is blank. Assuming you have no gaps in your data, the below would work:
Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1).Select
 
Upvote 0
Thanks very much njimack
That was simple - shows I know very little - I thought you needed to write a loop or something.

One more question if I may - if I want to copy a range that starts with A1 and ends with the last non-empty cell how to I write that?

Thanks.
 
Upvote 0
Thanks- I just saw your 2nd post and was going to mention that as I just tested it.
If you can please help me with my 2nd question which is also fairly simply but yet beyond me that would be great.

Thanks.
 
Upvote 0
One more question if I may - if I want to copy a range that starts with A1 and ends with the last non-empty cell how to I write that?

You haven't said what you want to do after you've copied it. The below line of code will copy the range.

Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Copy
 
Upvote 0

Forum statistics

Threads
1,203,538
Messages
6,055,990
Members
444,839
Latest member
laurajames

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top