Excel Failure

tdurbin

New Member
Joined
Sep 16, 2002
Messages
6
First of all apologies, really simple query I think.

Anyway I have a lengthy spreadsheet that is being used as a customer order form. Each row after the top 39 is a different item. When I print it though, I only want to include the top 39 rows, rows that have an "x" in a certain cell, and the bottom 4 rows.

IS this possible? I am happy to pay for a fix, but it is quite urgent!

Cheers and here's hoping.

TD
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
You could use a macro to hide the rows before printing. I'll have a go if you tell me:

1. The name of the sheet.
2. The rows you want to check (40 to ??).
3. Which column contains the "x".
 

tdurbin

New Member
Joined
Sep 16, 2002
Messages
6
Mr Poulsom, you are a gentleman!

The sheet is called order and I need to keep the first 39 rows.

The column with the "x" is L, and the last 2 rows 322 & 323 need to be kept.

Let me know if this can be done, and thank you very much.

Cheers

Tom
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try this:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim Rng As Range
    Dim c As Range
    If UCase(ActiveSheet.Name) <> "ORDER" Then Exit Sub
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Set Rng = Range("L40:L321")
    For Each c In Rng
        If UCase(c.Value) = "X" Then
            c.EntireRow.Hidden = True
        End If
    Next c
    Cancel = True
    ActiveSheet.PrintOut
    Rng.EntireRow.Hidden = False
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub

In case you're not familiar with macros, right click the XL logo to the left of File on the menu and choose View Code. Paste the code in the window on the right.

Then print your worksheet.
 

tdurbin

New Member
Joined
Sep 16, 2002
Messages
6
Thank you so much for this.

Just to check, does it automatically run when I press the print icon, or do I have to run a macro?
 

tdurbin

New Member
Joined
Sep 16, 2002
Messages
6
Thank you so much for this.

Just to check, does it automatically run when I press the print icon, or do I have to run a macro?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
It will run whenever you print the sheet (from icon or menu).

You can't run the macro - it's Private.
 

tdurbin

New Member
Joined
Sep 16, 2002
Messages
6
All apologies, but I've followed your instructions to the letter and it doesn't seem to work....

Any chance I can e-mail you the sheet?

So sorry again and Thank you.

TD
 

Forum statistics

Threads
1,181,463
Messages
5,930,082
Members
436,718
Latest member
messa57fr

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