macro to delete empty cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Guest
Hi Guys!

Here's the deal:

I have this template invoice, and I am reserving 1,000 or so cells in the "Item" column (A1), because I know that every month when I create the invoice for that period, this is the maximum number of items I will need to list. The thing is, sometimes I may only have 300, 400, etc., and I don't want to have all the extra empty cells there. In other words, if let's say I have 550 items for the month, (A1:A550 contain text). I want excel to recognize this and "autofit" by deleting the entire row range of A551-A1000. I would like two things- a macro to achieve this purpose, and then also another marco to restore the sheet, back to the original 1,000 lines, without any text. Any ideas? Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Any ideas? If I haven't explained it well enough, I can give it another try, just let me know!
 
Upvote 0
Any ideas? If I haven't explained it well enough, I can give it another try, just let me know!
 
Upvote 0
Perhaps if I write in English how i think the code for the macro will look, it might be easier:

For the range A1:A1000, delete all rows where the cell is empty

(i.e.- if A500 thu A1000 are empty, these rows will be deleted...)
 
Upvote 0
Assuming that when an item is entered there will always be data in column A :-
[A1:A1000].SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True

Post again if the assumption is wrong.

To clear all the cells :-
[A1:A1000].ClearContents

To display all the rows :-
[A1:A1000].EntireRow.Hidden = False

Note : You could have created code to do what you want with the macro recorder.
 
Upvote 0

Forum statistics

Threads
1,223,516
Messages
6,172,777
Members
452,477
Latest member
DigDug2024

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