CTRL+End is on row 133 at the end of a macro, but is on row 17 (last row of data) after closing and re-opening the workbook. Why?

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I just got some code from some great folks earlier today and I thought my problem was fixed until I re-ran the code again.

Here's what's going on....

I have a sub (called mod0) that calls 3 modules; mod1, mod2, mod3.

When I run the full routine, calling all three modules, CTRL+End brings me to row 133, when in fact my last row of data is row 17.

However, if I set a breakpoint and stop BEFORE mod3 runs, save the workbook, close it, re-open it and run mod 3 by itself, CTRL+End brings me to a cell in row 17; just like it should.

This is so frustrating. Why would closing and re-opening the workbook change the last cell with "something" in it?

Why can't I just call mods 1,2 & 3 and have CTRL+End go to a cell in row 17 without any interruptions?

Any thoughts on this would really be appreciated.

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
It's a weird little quirk (may be a bug, but it's known and documented).

I assume your macro is deleting rows.
Basically it remembers what the lastcell 'WAS' before rows got deleted.
Saving the book resets that property.

Another way is to reference UsedRange in your code.
Don't even need to actually 'Do' anything with it, just put the reference in there somewhere.
That will also reset the lastcell.

So just add this where you put your breakpoint

ActiveSheet.UsedRange
 
Upvote 0
Wowwwwwwwwwwwwwwwwwwwwwwwwwwww,

I think that is the single best line of code EVER CREATED!

Thanks soooooo muchhhhhh!
 
Upvote 0

Forum statistics

Threads
1,214,559
Messages
6,120,208
Members
448,951
Latest member
jennlynn

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