Remove empty rows (containing formulas) before printing

geertech

Board Regular
Joined
Dec 10, 2008
Messages
56
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet for invoicing with several tabs, for my own reference and calaculations and one for printing the actual invoice to customers.

The printing tab has formulas refering to the 'input' tabs, that obviously in a lot of cases has too many rows as there's not so much to invoice.

I would like to remove the empty rows (they do contain the formulas and some formatting) before printing, but can't seem to find a solution, tried several suggestions, and recording macro's but no luck so far...

Would anyone be able to resolve this?

Thanks a million,
Remco
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe something like this
Of course, change the column reference
VBA Code:
Sub MM1()
ActiveSheet.Columns("A").SpecialCells(xlCellTypeFormulas).EntireRow.Delete
End Sub
 
Upvote 0
Maybe something like this
Of course, change the column reference
VBA Code:
Sub MM1()
ActiveSheet.Columns("A").SpecialCells(xlCellTypeFormulas).EntireRow.Delete
End Sub
Thanks Michael, but it gives me a runtime error 1004, although I've set the trust center to allow macro's...
 
Upvote 0
Did you use the correct column ref.
Also, the macro willerror if nothing is found.
 
Upvote 0
Did you use the correct column ref.
Also, the macro willerror if nothing is found.
No, I didn't, silly...
When pointing to the correct column it works, but deletes the non-empty rows as well though..
 
Upvote 0
Maybe this then
Rich (BB code):
Sub MM2()
Dim lr As Long, r As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    For r = lr To 2 Step -1
        If Range("D" & r).HasFormula() = True And Range("A" & r).value = "" Then Rows(r).Delete
    Next r
End Sub

Rememeber, change the "D" to the column that has the formulas !!!
 
Upvote 0
Solution
Maybe I am missing something but could you not set the print range to the range excluding the "empties" that have formulae?
 
Upvote 0
I suggest that you highlight the column(s) or row(s). And if you press and hold the control key, so you can select additional column(s) or row(s) which are not adjacent. Then right-click the selected column(s) or row(s) and select hide. It hides it and it does not interfere with any formulas at all. After you print it, you can unhide it. Hope it helps.
 
Upvote 0
Maybe this then
Rich (BB code):
Sub MM2()
Dim lr As Long, r As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    For r = lr To 2 Step -1
        If Range("D" & r).HasFormula() = True And Range("A" & r).value = "" Then Rows(r).Delete
    Next r
End Sub

Rememeber, change the "D" to the column that has the formulas !!!
Hi Micheal,
Changed If Range("D" & r).HasFormula() = True And Range("A" & r).value = "" Then Rows(r).Delete
value = ""to value = Empty, thenj it runs like a charm!

Thanks so much for your support!
Cheers,
Remco
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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