Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

Excel print range

I have a macro that I use to print a range of cells.  If it does not = 0 then it prints.  It worked until I tried the same macro in the Excel 2010 - it works except that it prints all - even if the sum is zero.

Any help is appreciated.

For x = 6 To 19
    If Sheet2.Cells(x, 8).Value <> 0 Then
        y = x - 3
        Sheets(y).Select
        ActiveSheet.PageSetup.PrintArea = "$B$2:$F$21"
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
        End If
   Next x

  For x = 6 To 19
    If Sheet2.Cells(x, 11).Value <> 0 Then
        y = x - 3
        Sheets(y).Select
        ActiveSheet.PageSetup.PrintArea = "$I$2:$M$21"
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
        End If
   Next x
For x = 6 To 19
    If Sheet2.Cells(x, 14).Value <> 0 Then
        y = x - 3
        Sheets(y).Select
        ActiveSheet.PageSetup.PrintArea = "$b$22:$f$41"
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
        End If
   Next x
For x = 26 To 39
    If Sheet2.Cells(x, 14).Value <> 0 Then
        y = x - 23
        Sheets(y).Select
        ActiveSheet.PageSetup.PrintArea = "$I$22:$M$41"
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
        End If
   Next x
End Sub
Avatar of HomerTNachoCheese
HomerTNachoCheese

Have you tried inserting a breakpoint at the beginning of your code, then step through the code to check the values line by line?
Avatar of JohnMac328

ASKER

No - trying to help someone out - not an excel person :)
Maybe the values are not really 0 and need to be rounded:
Example:
Round(Sheet2.Cells(x, 14).Value, 2)

Open in new window


Adjust ',2' up to the number of digits needed.
ASKER CERTIFIED SOLUTION
Avatar of dlmille
dlmille
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"The test is for 0 so rounding should not b an issue"
-> I did actually run in this kind of issue in the past where the sum of values looked as if it was zero, but they were not.  In the end these are floating point numbers and rounding will make a near zero a perfect zero.
I withdraw my comment, you are absolutely correct. 00000000001 may be zero to excel.

Let's see what the test I submitted provides and hopefully there's some answer there as well.

Cheers,

Dave