Checkboxes

vmpascual

New Member
Joined
Apr 6, 2011
Messages
2
I want to print the invoice by checking one or more of the 4 checkboxes. My workbook contains 2 sheets, data sheet and the invoice sheet. My user form contains 4 checkboxes, one print Command Button and on cancell button. When i run the program, i get the error: "Select method of class failed. Following is the code in the print command button..

Private Sub OKButton_Click()
If UserForm1.CheckBox1.Value = True Then
Range("A5").Select
ActiveWorkbook.Names.Add Name:="Start", RefersToR1C1:="=Data!R5C1"
Range("Start").Select
Do While ActiveCell.Value <> Empty
If ActiveCell.Value = 1 Then ActiveCell.Range("A1:T1").Copy Range("A1")
If CheckBox1.Value = True _
Then Sheets("Invoice").Range("A62") = "Account Receivable Copy"
End If
If CheckBox2.Value = True _
Then Sheets("Invoice").Range("A62") = "Remittance Copy - Please return with payment"
End If
If CheckBox3.Value = True _
Then Sheets("Invoice").Range("A62") = "Tenant Copy"
End If
If CheckBox4.Value = True _
Then Sheets("Invoice").Range("A62") = "Tenant File Copy"
End If
If ActiveCell.Value = 1 Then Sheets("Invoice").PrintOut
If ActiveCell.Value = 2 Then ActiveCell.Offset(0, 0).Select
ActiveCell.Offset(1, 0).Select
Loop
End If
Unload UserForm1
End Sub

Hope you could help me guys.

Thanks,
vmpascual
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Sometimes random messages pop up when you forget to close a block.

It looks like you might be missing an "End If" that should close the first if-block?

Edit: Never mind, I'm putting it in excel's VBA editor now. It's hard to read the way you posted it. I'll repost it with code tags.
 
Upvote 0
Code:
Private Sub OKButton_Click()
 
If UserForm1.CheckBox1.Value = True Then
    Range("A5").Select
    ActiveWorkbook.Names.Add Name:="Start", RefersToR1C1:="=Data!R5C1"
    Range("Start").Select
 
    Do While ActiveCell.Value <> Empty
        If ActiveCell.Value = 1 Then ActiveCell.Range("A1:T1").Copy Range("A1")
 
        If CheckBox1.Value = True _
        Then Sheets("Invoice").Range("A62") = "Account Receivable Copy"
        End If
 
        If CheckBox2.Value = True _
        Then Sheets("Invoice").Range("A62") = "Remittance Copy - Please return with payment"
        End If
 
        If CheckBox3.Value = True _
        Then Sheets("Invoice").Range("A62") = "Tenant Copy"
        End If
 
        If CheckBox4.Value = True _
        Then Sheets("Invoice").Range("A62") = "Tenant File Copy"
        End If
 
        If ActiveCell.Value = 1 Then Sheets("Invoice").PrintOut
 
        If ActiveCell.Value = 2 Then ActiveCell.[COLOR=red]Offset(0, 0)[/COLOR].Select
 
        ActiveCell.Offset(1, 0).Select
 
    Loop
 
End If
 
Unload UserForm1
 
End Sub

If the red text is necessary, I don't see why.

I don't see anything obviously wrong that should be causing it to fail though.

Have you tried just ommenting out the lines that select ranges? They don't seem particularly necessary either. Or tried replacing them with "Activate"?

It also seems like a good idea to throw in some sheet references ahead of your ranges;

set a = ThisWorkBook.Sheets("sheet name")
 
Upvote 0
Thanks Glory,

My problem is the printing of the same one invoice template where only the description would change in Range("A60"). The code prints only one checkbox even if I checked all the checkboxes. Checkbox1 should always be checked in order to print the other checkbox. No printing will happen if Checkbox1 is unchecked.

please let me know where i should place in the code the "set a = ThisWorkbook.Sheets("Invoice")

Thanks in advance again if you could help me.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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