Mulpitle If statements in a Macro

tony666

New Member
Joined
Oct 12, 2010
Messages
10
Hi All,

I have this macro code where it has more than 2 if statements in it. When I run them it ignores the second If statements being valid even though it is not. The if statement highlighted in bold is being treated as if the Value in C63 =0 eventhough it is not... Is there a VBA guru who can help on this please?

Many thanks..


For Each myCell In myRng.Cells
With myCell
If IsEmpty(.Offset(0, -1)) Then
'if the row is not marked, do nothing
Else
.Offset(0, -1).ClearContents 'clear mark for the next time
For iCtr = LBound(myAddresses) To UBound(myAddresses)
FormWks.Range(myAddresses(iCtr)).Value _
= myCell.Offset(0, iCtr).Value
Next iCtr
Application.Calculate 'just in case
'after testing, change to Preview to False to Print
'FormWks.PrintOut Preview:=True

Sheets("FINAL STATEMENTS").Select
Range("A1:E132").Select
Range("A1").Activate
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.Zoom = 90
End With

Selection.PrintOut Copies:=1, Collate:=True
Range("A133:K190").Select
Range("A133").Activate
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.Draft = False
.Zoom = 65
End With
Selection.PrintOut Copies:=1, Collate:=True

Sheets("LH STATEMENTS - THIS YEAR").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

Sheets("BUDGET vs ACTUAL").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True




Sheets("APPENDIX - A").Select
With ActiveSheet.PageSetup
.CenterHorizontally = True
.CenterVertically = False

End With
If Worksheets("WORKINGS").Range("C36", "C42", "C55").Value = 0 Then
ActiveWindow.SelectSheets.PrintOut Copies:=0, Collate:=False
' this is ommitting Appendix A when there is no repair costs

Else

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If


If Worksheets("WORKINGS").Range("C63").Value = 0 Then
ActiveWindow.SelectSheets.PrintOut Copies:=0, Collate:=False
Else
' this is ommiting the Appendix B when there is no Snking Fund Value

Sheets("APPENDIX - B").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try

Code:
If Worksheets("WORKINGS").Range("C36").Value = 0 Or Worksheets("WORKINGS").Range("C42").Value = 0 Or Worksheets("WORKINGS").Range("C55").Value = 0 Then
    ActiveWindow.SelectSheets.PrintOut Copies:=0, Collate:=False
 
Upvote 0
Hi Peter,
Thanks so much for this.. But wouldn't only run true only one of these cells c36 or c42 or c55 equal 0? I want this happen when all conditions are met..

Try

Code:
If Worksheets("WORKINGS").Range("C36").Value = 0 Or Worksheets("WORKINGS").Range("C42").Value = 0 Or Worksheets("WORKINGS").Range("C55").Value = 0 Then
    ActiveWindow.SelectSheets.PrintOut Copies:=0, Collate:=False
 
Upvote 0
In that case it neds to be And instead of Or

Rich (BB code):
If Worksheets("WORKINGS").Range("C36").Value = 0 And Worksheets("WORKINGS").Range("C42").Value = 0  And Worksheets("WORKINGS").Range("C55").Value = 0 Then
    ActiveWindow.SelectSheets.PrintOut Copies:=0, Collate:=False
 
Upvote 0
Hi Peter,

When I include this code the macro does not run the way it should.

Well satisfies the first condition since c36/c42/c55 are all equil to 0.

But the second if statement c63 does not equil to 0 and it ignores that bit and there is not print out... What might be causing it?

Every time I take off the first if statements everything seems to work ok and all printed out. When I include it it does what I had mnentioned above..


In that case it neds to be And instead of Or

Rich (BB code):
If Worksheets("WORKINGS").Range("C36").Value = 0 And Worksheets("WORKINGS").Range("C42").Value = 0  And Worksheets("WORKINGS").Range("C55").Value = 0 Then
    ActiveWindow.SelectSheets.PrintOut Copies:=0, Collate:=False
 
Upvote 0
Maybe because of a typo

Rich (BB code):
If Worksheets("WORKINGS").Range("C63").Value = 0 Then
    ActiveWindow.SelectedSheets.PrintOut Copies:=0, Collate:=False
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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