Hiding row if first cell is empty (VBA)

K

Khalil Handal

Hi,
I have a worksheet (sheet2) used as a report. It should be printed on ONE
page A4 size.
Some rows between 7 and 25 have the first cell empty (no value is shown).
The values in the range A7:A25 are copied from another sheet (sheet1).
I need:
1- VBA code or Macro to hide the rows were the corresponding cell in the
range A7:A25 is empty.
2- the sheet to be printed on ONE A4 paper

Is this Possible??

Khalil
 
G

Gord Dibben

Easiest method may be to record a macro whilst using the Autofilter to show
non-blank rows then set your printrange and paper size.

The rows hidden by the filter will not print.

To get you started...........................

This macro will hide the rows that have a blank cell in column A.

You can record a macro whilst setting a printrange and paper size.

Incorporate the two.

Sub hide_zero_rows()
Dim c As Range
With ActiveSheet.Range("A7:A25")
Do
Set c = .Find("", LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False)
If c Is Nothing Then Exit Do
c.EntireRow.Hidden = True
Loop
End With
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top