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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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
 
Upvote 0
You can then stick a sh.PrintOut at the end if you want the macro to print it as well.
 
Upvote 0
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)
 
Upvote 0

Forum statistics

Threads
1,214,579
Messages
6,120,365
Members
448,956
Latest member
Adamsxl

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