Using input box to define variable

gwladys

New Member
Joined
Apr 2, 2005
Messages
34
I've included a few print macros in a Excel file, helped along the way in this forum.

The macro works when a checkbox is ticked. The output in this case is cell J4.

I've defined a variable (printfilling) which is then used to define number of copies to be printed. Obviously I could just leave the number in the main part of the macro.

But I would like to enable the user to define the value of the variable using an input box.

Any help gratefully received.




Sub filling()
'
' filling Macro
'
Dim printfilling As Integer
printfilling = 3

If Range("j4") = True Then
ActiveSheet.PageSetup.PrintArea = "$b$41:$ac$68"
ActiveWindow.SelectedSheets.PrintOut Copies:=printfilling, Collate:=True, IgnorePrintAreas:=False
With ActiveSheet.PageSetup
.Orientation = xlLandscape
End With
Else
Range("j4").Select
End If

End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try this

VBA Code:
Sub filling()
'
' filling Macro
'
Dim printfilling As Integer
printfilling = InputBox("Please enter the amount of copies you require", "Print")

If Range("j4") = True Then
ActiveSheet.PageSetup.PrintArea = "$b$41:$ac$68"
ActiveWindow.SelectedSheets.PrintOut Copies:=printfilling, Collate:=True, IgnorePrintAreas:=False
With ActiveSheet.PageSetup
.Orientation = xlLandscape
End With
Else
Range("j4").Select
End If
End Sub
 
Upvote 0
Hi Trevor, that works, many thanks.

There is just one issue: ticking the checkbox makes the input box work and the macro run, but unticking also makes the input box work, although it won't print.
Is there any command that will untick a checkbox at the end of a macro?
 
Upvote 0
Whats the name of the Checkbox and what type of Checkbox are you using? Form Control or ActiveX Control.
 
Upvote 0
I'm using Form Control and J4 is the cell link.

As for the name, I've looked in several places and can't find out either what it is or how to change it.
 
Upvote 0
When you right click the checkbox the name will appear in the name box next to the formula bar.

Add this line of code below the end if and it should switch back to unchecked.

VBA Code:
 ActiveSheet.Shapes("Check Box 1").ControlFormat.Value = -4146
 
Upvote 0
That's very useful to know. The whole of google didn't explain it as well. Works a treat, thank you very much...
 
Upvote 0
Happy to help and thanks for letting me know (y)
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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