Terminate Macro At Last Cell

timstring

New Member
Joined
Feb 6, 2013
Messages
30
I need for my Macro to stop when it reaches the last cell. I know the last cell coordinates. I need something like:

Code:
  Loop Until ActiveCell.Offset(1, LastCol - 1) = **coordinates of last cell**

How would I accomplish this?

ty in advance
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It would help if we could see the rest of the code.

Personally, My macros almost never activate a cell. So inside my loop I would be referencing cells(CurrRow,CurrCol)

If you are activating cells as you go, you can check ActiveCell.row <= lastRow
 
Upvote 0
Hi,

You could save the coordinates of the last cell and compare it to the looping cell:
LastCellAddr = cells(x,y).address 'x,y are the coordinates of the last cell
Loop Until ActiveCell.Offset(1, LastCol - 1).address = LastCellAddr

.Address returns the cell's address similar to "$c$2"

Succes,

Paul
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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