Problem with "Do Until IsEmpty(ActiveCell)"

Snort

New Member
Joined
Sep 15, 2023
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I created a macro that, among other things, cycles through the column headings standardizing the heading of relevant columns. I loop through the columns by

VBA Code:
 Range("A1").Select

Do Until IsEmpty(ActiveCell)

    blah blah blah
    
    ActiveCell(1, 2).Select
    
Loop

This works great with no problems as far as I can tell on most sheets I run it on, but every now and then there are times when it goes all the way to column XFD (which causes problems with the rest of the macro) and I can't figure out why.
  • I'll hit Control + End on the problem sheet and it'll show the last cell is in column AY for example. Run the macro, and Control+End now brings me to column XFD.
  • I go one column over from wherever Control + End brings me on the problem sheet, use the immediate window and get a TRUE result from "debug.print IsEmpty(ActiveCell)", yet the macro still runs to column XFD
  • I've tried using ASAP Utilities to "Reset Excel's Last Cell" and still get the same result on the problem sheet. Column XFD.
Any idea's on what's causing this on some sheets but not most?
Do you have a better method to loop through the populated cells in Row 1? The number of columns changes per sheet based on the source of the data.

Thanks for your help!
 
You are welcome.

Note: I changed the post that you marked as the solution. You may to mark the post that answers the initial question in the first post (not other follow-up questions).
Thanks
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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