Simple VBA for print macro

gwladys

New Member
Joined
Apr 2, 2005
Messages
34
Not simple enough for me, unfortunately. It's many years since I worked on VBA and it's true that if you don't use it you lose it. I guess this is very basic stuff

I'm linking macros to checkboxes. If a checkbox is ticked this will run a simple print macro. If it's unticked then nothing should happen. But I keep getting compile errors, either " end if without block if" or "else without if".

I've changed it around a bit but at the moment the script is:

Sub line1()
'
' line1 Macro
'

' If range("L5") = true then
Range("K17:L18").Select
ActiveSheet.PageSetup.PrintArea = "$K$17:$L$18"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
Else
Range("K17").Select
End If
End Sub

Appreciate any help. I know this is something most here can do in their sleep.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You could do something like this

VBA Code:
Sub line1()
'
' line1 Macro
'
    If CheckBox1.Value = True Then
        If range("L5") = True Then
            Range("K17:L18").Select
            ActiveSheet.PageSetup.PrintArea = "$K$17:$L$18"
            ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
        Else
            Range("K17").Select
        End If
    End If
End Sub
 
Last edited:
Upvote 0
Thanks. decadence,

I'm sure it's nearly there. Probably what I didn't account for that there are two logical variables. I guess that CheckBox1.Value is the tick. L5 is the output cell (the checkbox itself is in cell M5).

However, does CheckBox1 refer to a name? I'm having difficulty finding the names of these objects. So I created a new checkbox called Checkbox10.

When I run the macro using either checkbox1 or checkbox10 I get the same error:

Run-time error '424':

Object required.

So there could be an issue with the object name.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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