14

Pressing Ctrl+End in Excel takes you to the bottom-right-most cell of the worksheet.

If you delete the last rows or columns and save the workbook, this last cell gets updated, as well as the scrollbars.

I remember there was a one line VBA command that you could run that would do the update without having to save the workbook, but I can't remember what the command is - do you have any ideas?

2
  • 1
    try macro : ActiveSheet.UsedRange but its often doesn't work
    – Qbik
    May 29, 2014 at 13:18
  • Does not work in Excel 2003 or Excel 2010
    – antonsachs
    Dec 15, 2020 at 17:07

9 Answers 9

27

I’ve found something that consistently works to delete those blank rows. You can tell when the “used range” excel is using is too big and is going to add extra blank rows when you use the scroll bar to the right and it goes beyond the last row of actual data when you scroll to the bottom. This will caused extra blank records to be added to the table when it is imported into SQL.

To get rid of them:

  1. Select the entire first row under the last row of data. Hit Ctrl + Shift + Down Arrow to select all the blank rows.
  2. From the Home Tab Select Clear and then Clear All from the Edit menu (picture of a whitish-grey eraser).
  3. Right-click and select Delete.
  4. Goto cell A1 first and then Save.
  5. Press Ctrl + Home and then Ctrl + End (This should take you the correct last cell in the used range (above blank rows).
  6. Click Save again.
3
  • That is exactly what is NOT to be done. The workaround to save the file was stated in the original post and the question was how to do it without saving.
    – Michael S.
    Feb 16, 2018 at 16:18
  • @MichaelS. Sorry, but IMHO this is the simplest way for regular users to shrink the active cell range to those with real user data. I have the same problem with my users and the only way stated by MS is copying data to another blank file, save, delete the original one and rename. If the workbook has N sheets, you have to copy N sheets to another file, save and rename, so this solution is far way better, but not perfect as stated. Jan 22, 2021 at 9:37
  • This works in Excel 2016 as of version 2107 (16.0.14228.20204). Step 2 should be reworded: On the Home Tab in the "Edit" group/section of icons, click the "Clear" dropdown menu button, then in the dropdown menu, click "Clear All". If there is a large number of empt rows to remove, the "Clear All" will take a while, and the Excel window titlebar will likely say "Not Responding", but it will work. If after doing the clear, you get message about using too much memory, click the save icon, close the file, then re-open it and continue to remove unused rows from other sheets.
    – Gen1-1
    Aug 4, 2021 at 21:11
17

Here is the answer:

Sub x()
    ActiveSheet.UsedRange
End Sub

Run this and the last cell will be reset.

1
  • Doesn't work in Excel 2013 -- granted I was given a workbook with hidden functions and other cruft, so something may be conflicting. Aug 11, 2016 at 13:15
11

When none of the above works try this.

Select the unused rows and change the row height.

Now delete the rows and save.

Bingo!

5
  • This one worked perfectly for me in Excel 2016 (while running ActiveSheet.UsedRange) and trying the Clear --> Clear All thing all failed). Thanks!!! :) Aug 31, 2018 at 5:24
  • This is what fixed it for me!!! I was banging my head on the wall trying to fix this, and this actually worked. Thank you SO much!
    – Krysteel
    Mar 29, 2019 at 20:27
  • thank you man, this is a miracle within Excel bugs, but your solution worked Keep in mind you need to select the rows (not just cells) by clicking the first row, then scrolling down and clicking the last row number.
    – Vlad
    Jun 24, 2019 at 19:58
  • 1
    Thanks. I had a look into why this works. Within the original Excel file (in XML that makes up the XLSX) all of the blank rows (from row 1000 to 1 million) every row had the customHeight="1" attribute set. This stops all of the other methods described on this page from working. Deleting rows replaces them with new rows with customHeight="1" set, so the dimension is never reset back. Changing row height clears this. In the <sheetFormatPr> element (has default values for new rows/columns), customHeight="1" was also set, so new rows picked up the same problem. Definitely a bug Microsoft!!
    – cbailiss
    Feb 4, 2020 at 17:12
  • Worked for me when other methods failed. Thanks for this. Such a simple idea, but one to remember for future use!
    – AdamV
    Aug 11, 2022 at 14:54
1

Here's what I did... since none of the above worked (this time that is, which is sad cause this code was running beautifully then all the sudden xlCellTypeLastCell totally failed me.) This will only work if you hardcode the first cell of the region you wanna grab the last cell of... for example I was pasting data tables into a sheet of 12 - 40 columns and 60-90 rows... but since it was a paste, it always started in cell A79...

Worksheets("Data_Import").Activate
Range("A79").CurrentRegion.Select
A = Selection.Rows.Count - 1
B = Selection.Columns.Count - 1
Selection.Offset(A, B).Resize(1, 1).Select
Set DataEnd = Selection

I feel sad to NOT use the cool special cells thing, but alas, if it doesn't work! then I just can't use it. :C

p.s. - you could also throw in a

ActiveSheet.Cells(Rows.Count, 1).End(xlUp).CurrentRegion.Select
0

This solution works for Excel 2013, but may also work for most recent versions of Excel:

  • Choose the worksheet where you want to change the last cell, and delete any unused rows and columns
  • Click on File - Options - Customize Ribbon
  • Under Main Tabs, check the box next to "Developer", then click OK
  • On the Developer ribbon that now appears, click Visual Basic
  • In the upper-left corner, under Microsoft Excel Objects, click on the Sheet Name where you want to force a refresh of the worksheet's last cell
  • In the menu, click on Run - Refresh, then close the Visual Basic Window

When you hit Ctrl + End, your last cell should now be refreshed.

0

Check out http://dmcritchie.mvps.org/excel/lastcell.htm#MakeLastCell, found the link from a similar question.

Far from the forgotten one liner, but did solved the problem for me.

Alternatively;

  1. Turn on manual calculation (to preserve references).

  2. create new sheet.

  3. Copy cells and Name of old sheet.

0

For some reason the code ActiveSheet.UsedRange alone did not work for me on Excel 2016 64-bit to force Excel to reset the last used cell.

This does work for me. Hope this helps.

Rows(25:415).Clear   'deletes contents and formatting
ActiveSheet.UsedRange   'resets last used cell
0

The solution to change row height to zero and saving worked. Reopen, set row height to 12 and notice that End Home is no longer at the very bottom right of the worksheet.
THANK YOU. I have been working on this for over two years.

Jim Champaigne Elkhart, Indiana

1
-2

I'm not sure why everyone is making it so complicated. Just press Ctrl + PgDn.

1
  • Select the last cell you want first.
    – Brian
    Nov 5, 2019 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.