Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

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

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

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Example:

```
Round(Sheet2.Cells(x, 14).Value, 2)
```

Adjust ',2' up to the number of digits needed.

```
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
```

To

```
If Sheet2.Cells(x, 8).Value <> 0 Then
y = x - 3
With Sheets(y)
.PageSetup.PrintArea = "$B$2:$F$21"
.PrintOut copies:=1
End With
End If
```

There's no need to select sheets or use the ActiveWindow to set print areas or print sheets.

I just tested your code out with dummy data and it worked fine for me. I put a 1 in H6, K6, N6, and N26 and it printed 4 times.

The test is for non-zero so rounding should not be an issue. Just check those ranges and advise if the value is not zero. If that doesn't work, then try this and see what it tells you:

You can try this amended code below which creates a LogSheet (assuming the workbook is not protected) and logs what is happening. Check the log and see what values are being displayed for these ranges. If you are getting nothing, then the ranges being examined don't have data - or at least they don't have non-zero data, and that's what the if statement is looking for.

Please advise.

```
Sub test()
Dim wkb As Workbook
Dim wksNew As Worksheet
Dim outCursor As Range
Set wkb = ThisWorkbook
On Error Resume Next
Set wksNew = wkb.Worksheets("Log Sheet")
If Err.Number <> 0 Then
Set wksNew = wkb.Worksheets.Add(after:=wkb.Worksheets(wkb.Worksheets.Count))
wksNew.Name = "Log Sheet"
End If
On Error GoTo 0
wksNew.Cells.Clear
Set outCursor = wksNew.Range("A1")
For x = 6 To 19
outCursor.Value = "BLOCK 1 Sheet2.Cells(" & x & ",8).Address is = " & Sheet2.Cells(x, 8).Address & " having value: " & Sheet2.Cells(x, 8).Value
Set outCursor = outCursor.Offset(1, 0)
If Sheet2.Cells(x, 8).Value <> 0 Then
y = x - 3
With Sheets(y)
.PageSetup.PrintArea = "$B$2:$F$21"
.PrintOut Copies:=1
End With
End If
Next x
For x = 6 To 19
outCursor.Value = "BLOCK 2 Sheet2.Cells(" & x & ",11).Address is = " & Sheet2.Cells(x, 11).Address & " having value: " & Sheet2.Cells(x, 11).Value
Set outCursor = outCursor.Offset(1, 0)
If Sheet2.Cells(x, 11).Value <> 0 Then
y = x - 3
With Sheets(y)
.PageSetup.PrintArea = "$I$2:$M$21"
.PrintOut Copies:=1
End With
End If
Next x
For x = 6 To 19
outCursor.Value = "BLOCK 3 Sheet2.Cells(" & x & ",14).Address is = " & Sheet2.Cells(x, 14).Address & " having value: " & Sheet2.Cells(x, 14).Value
Set outCursor = outCursor.Offset(1, 0)
If Sheet2.Cells(x, 14).Value <> 0 Then
y = x - 3
With Sheets(y)
.PageSetup.PrintArea = "$b$22:$f$41"
.PrintOut Copies:=1
End With
End If
Next x
For x = 26 To 39
outCursor.Value = "BLOCK 4 Sheet2.Cells(" & x & ",14).Address is = " & Sheet2.Cells(x, 14).Address & " having value: " & Sheet2.Cells(x, 14).Value
Set outCursor = outCursor.Offset(1, 0)
If Sheet2.Cells(x, 14).Value <> 0 Then
y = x - 23
With Sheets(y)
.PageSetup.PrintArea = "$I$22:$M$41"
.PrintOut Copies:=1
End With
End If
Next x
End Sub
```

Cheers,

Dave

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial-> 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.

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

Cheers,

Dave

Microsoft Excel

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.