• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Selective Print Option

Hi!


I have been trying to create a macro that will recognize that if a cell contains a 3 the macro will print out one range and if it contains anything else it will print out another range.


I had thought this would be comparatively simple but no matter what I do I get A1:J77 and cannot get the other option K1:U77 to print.

Can anyone tell me where I have gone awry?

[pre]
Code:
Sub PrintNotice()
'
' PrintNotice Macro
' Prints out dispute notice or rebill sheet
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Cells.Select
Range("A1").Activate
ActiveWindow.DisplayZeros = False
Cells.Select
Application.DisplayCommentIndicator = xlCommentIndicatorOnly

If (G116) = 3 = False Then
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$77"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

If (G116) = 3 = True Then
ActiveSheet.PageSetup.PrintArea = "$K$1:$U$77"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else

End If

End If
End Sub
[/pre]
 
You have a double comparison with the G116 = 3 = True. I think you are wanting to just write:

G116 = 3

and

G116 <> 3

Since there are only 2 conditions, you can use an If...Else type statement, like so:

[pre]
Code:
Sub PrintNotice()
'
' PrintNotice Macro
' Prints out dispute notice or rebill sheet
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Cells.Select
Range("A1").Activate
ActiveWindow.DisplayZeros = False
Cells.Select
Application.DisplayCommentIndicator = xlCommentIndicatorOnly

If Range("G116") = 3 Then
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$77"
Else
ActiveSheet.PageSetup.PrintArea = "$K$1:$U$77"
End If

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub
[/pre]
 
I am mystified. After receiving the response above which seemed to work I cannot recreate the situation and I have lost the spreadsheet that it worked in.


I have a cell that is supposed to act as a switch. If it is blank I want to use one print rage - if it isn't I want to use another. I tried using Isblank as a test but I couldn't get it to work, I then assigned another cell to test the switch cell and give it a value if it wasn't blank 1 or 3 if it was and I used the test you gave me above but it wont work.


My code is:

Cells.Select

Range("A1").Activate

ActiveWindow.DisplayZeros = False

Cells.Select

Application.DisplayCommentIndicator = xlCommentIndicatorOnly


If (F112) = 1 Then

ActiveSheet.PageSetup.PrintArea = "$A$1:$J$77"

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

Else


ActiveSheet.PageSetup.PrintArea = "$K$1:$U$77"

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

Application.DisplayCommentIndicator = xlCommentIndicatorOnly


End If


Application.DisplayCommentIndicator = xlCommentAndIndicator


End Sub


Regardless of the contents of F112 (either 1 or 3) I get the second print range. I don't understand where I am screwing up.
 
Hi, Mortadella!

What is F112? A variable, if so of what type; a cell reference, if so it's incomplete as it must be Range("F112")?

Regards!
 
There are three tick boxes that the user can put an x into on the worksheet or they can leave them blank. I had to test for three potentialities and that would be that the tick box cells could have an X or a 1 or be blank F112 is where the result of the tests kicks out numerically. If the number is above 2 it prints one report if it's less than 2 it prints out the other.
 
Back
Top