JohnMac328
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.Prin tArea = "$B$2:$F$21"
ActiveWindow.SelectedSheet s.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.Prin tArea = "$I$2:$M$21"
ActiveWindow.SelectedSheet s.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.Prin tArea = "$b$22:$f$41"
ActiveWindow.SelectedSheet s.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.Prin tArea = "$I$22:$M$41"
ActiveWindow.SelectedSheet s.PrintOut Copies:=1
End If
Next x
End Sub
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.Prin
ActiveWindow.SelectedSheet
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.Prin
ActiveWindow.SelectedSheet
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.Prin
ActiveWindow.SelectedSheet
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.Prin
ActiveWindow.SelectedSheet
End If
Next x
End Sub
Have you tried inserting a breakpoint at the beginning of your code, then step through the code to check the values line by line?
ASKER
No - trying to help someone out - not an excel person :)
Maybe the values are not really 0 and need to be rounded:
Example:
Adjust ',2' up to the number of digits needed.
Example:
Round(Sheet2.Cells(x, 14).Value, 2)
Adjust ',2' up to the number of digits needed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"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 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
Let's see what the test I submitted provides and hopefully there's some answer there as well.
Cheers,
Dave