Help with vba printout formulas

PANDA777

New Member
Joined
Aug 14, 2022
Messages
13
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hi I have a print input sheet with 3 cells to enter a number into.
Each input cell is linked to cell"C10" on each of the worksheets "1A""1B" & "1C"
I want to be able to link a vba code to a button to be able to only print out all sheets with numbers inputted.
eg. it would be 2 sheets printed only as per the input sheet below


1660680571105.png
1660681404934.png



The following formula below is in worksheet "A1" on the the cell c10 highlighted

=IF(Input!G43="","",Input!G43)

The following below code prints all three sheets out even if one of the input numbers is blank. I Think the Isempty statement is interpreting "" as a value
and therefore thinks it isn't empty.

Is there a way to fix this??

I'd also like the entry cells on the input sheet which printout to turn light green to reflect confirmation they've been sent to the printer if possible.

Here's the button code so far :

Sub Button32_Click()
Dim idx As Integer
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
If Not IsEmpty(ws.Range("c10").Value) Then
ws.PrintOut
End If
Next
End Sub

Much appreciate any help
 

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.
@PANDA777
As C10 contains a formula it will not return TRUE with IsEmpty.
You can test the cells Value against "" or vbNullstring
Assuming I have interpreted correctly and that the input cells are in G43 I43 and K43 then maybe the below will help?

VBA Code:
Sub Button32_Click()
Dim idx As Integer
Dim ws As Worksheet
Dim Col As Integer

For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = "Input" Then
    If Not ws.Range("C10").Value = "" Then
        Select Case ws.Name
            Case "1A"
            Col = 7
            Case "1B"
            Col = 9
            Case "1C"
            Col = 11
        End Select
        
        Sheets("Input").Cells(43, Col).Interior.Color = 11854022
        ws.PrintOut
    End If
 End If
Next
End Sub
 
Upvote 0
That's great thanks Snakehips!!! that works a treat. If I may can I ask one more tweak please if possible. I'd like the code to work in the background so it looks like after pressing the button the focus remains on the input sheet and maybe the button I just pressed? to execute the print command if that make sense.? Not sure if this can be achieved with Excel though.

Many thanks for your kind help !!
 
Upvote 0
@PANDA777 You are most welcome.
I cannot see why the above code would take the focus away from the input sheet?
 
Upvote 0
@PANDA777 You are most welcome.
I cannot see why the above code would take the focus away from the input sheet?

Hi again and thanks for replying. After the button press the command prints the right sheets but at the end
focus switches to sheet "1A" as below. Im using 2013 version of excel.

I thought it might of had something to do by printing to pdf, so I switched to my epson printer and it did the same.

Many Thanks once more

1660839464447.png
 
Upvote 0
Hi and thanks again. At the end of the command the focus switches to sheet "1A" for some reason. Im using 2013 excel.
I thought it might be because i was printing to pdf so I changed to my epson printer but the result was the same.

Many thanks once more

1660839966054.png
 
Upvote 0
Ok. Does it help to add a final line as below?
VBA Code:
Sheets("Input").Select. '<<<<<<<<<
End Sub
 
Upvote 0
Good to hear. Sorry, but that trailing period was a typo on my part.
 
Upvote 0

Forum statistics

Threads
1,215,401
Messages
6,124,705
Members
449,182
Latest member
mrlanc20

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