Print certain sheets if cell contains...

afc171

Board Regular
Joined
Jan 14, 2017
Messages
143
Office Version
  1. 2013
Platform
  1. Windows
Hi guys,

I have a print button which prints VBA PrintID1 but if in cell J:J contains the word EXP I want to run VBA PrintEXPForm. How would I do this?

VBA Code:
Sub PrintID1()

Dim Ref

Ref = Sheets("Goods-In").Range("AV6").Value

   Application.ScreenUpdating = False
   With Sheets("BRCodeCheck")
      .Visible = True
      .PrintOut Copies:=1, Collate:=True
      .Visible = False
   End With
   Application.ScreenUpdating = False
   
    MsgBox "Label Form Printed >" & Ref

Call ClearGI

End Sub

VBA Code:
Sub PrintEXPForm()

'EXCEPTIONPRODS - Prints EXP label form

Dim Ref

Ref = Sheets("ExceptionProds").Range("B4").Value

   Application.ScreenUpdating = False
   With Sheets("BRCodeCheckExp")
      .Visible = True
      .PrintOut Copies:=1, Collate:=True
      .Visible = False
   End With
   
   MsgBox "Label Form Printed >" & Ref

Call ClearSup2

End Sub

Thank you
 

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.
From your print button you could launch this macro that will choose which of the other two macros needs to be used. Maybe you will have to add reference to the sheet where Range J:J is to be checked. As it is it will check in the sheet that has the print button.
VBA Code:
Sub PrintMacro()
    Dim srch   As Variant
    Set srch = Range("J:J").Find(What:="EXP", LookAt:=xlWhole)
    If srch Is Nothing Then
        Call PrintID1
    Else
        Call PrintEXPForm
    End If
End Sub
 
Upvote 0
Solution
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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