printing rows that meet criteria

achiarotto

New Member
Joined
Jul 26, 2007
Messages
3
Hello all,

I have a small form with 2 columns(A,B) and 40 rows,
I only want to print row X if cell BX has data in it.
Is there an easy way to automate that or is the only way to manually hide the rows I don't want to have printed?

Any help would be appreciated.
Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

SteveO59L

Well-known Member
Joined
Apr 21, 2004
Messages
7,899
Try an auto filter, and use the custom option, where rows arent equal to
 

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
Perhaps this:
Code:
Sub PrintAreas()
Dim Limit As Long
Dim c As Long
Dim sh As Worksheet
Set sh = Worksheets("Sheet1")
With sh
    Limit = .Cells(Rows.Count, 1).End(xlUp).Row
    For c = Limit To 1 Step -1
        If .Cells(c, 2) = "" Then
            .Rows(c).Hidden = True
        End If
    Next c
    .PageSetup.PrintArea = "$A$1:$B$" & Limit
End With
End Sub
 

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
You can then stick a sh.PrintOut at the end if you want the macro to print it as well.
 

achiarotto

New Member
Joined
Jul 26, 2007
Messages
3
Sorry I should have stated that I have very basic excel knowledge.
Where would I place that VB Script?
 

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
Hit Alt+F11 to open the VB Editor. From here select Insert>Module and then paste the code into the big white screen!

You can then close the VB Editor and run the code like a Macro (Tools>Macro>Macros)
 

Forum statistics

Threads
1,181,055
Messages
5,927,861
Members
436,573
Latest member
CMR237

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
Top