Help with check box macro on new sheet

Production Planner

New Member
Joined
Apr 19, 2011
Messages
15
Hi ladies and gents,

I am having trouble getting the macro for the checkboxes on my template to copy across when I make a new sheet.

I currently have a macro that copies the template for me and asks for a new name.

Code:
Sub Picture3_Click()

    Dim sName As String
    Dim wks As Worksheet
    Worksheets("TEMPLATE").Copy after:=Sheets(Worksheets.Count)
    Set wks = ActiveSheet
    Do While sName <> wks.Name
        sName = Application.InputBox _
          (Prompt:="Enter new worksheet name")
        On Error Resume Next
        wks.Name = sName
        On Error GoTo 0
    Loop
    Set wks = Nothing
End Sub

This works fine but the issue lies in that when a check box on the new form is checked it does not do as it does on the template sheet.

here is the code for the template check box.

Code:
Private Sub CheckBox1_Click()

    With Sheet12
        If CheckBox1.Value Then
            Sheet12.Range("B4").Copy .Range("D4")
            .Range("B4").ClearContents
            

        End If
    End With
End Sub

The only thing I can see is that when the template is copied the code for the check box does not change the sheet name ie:Sheet12 to the number of the new sheet.

Is there anything I can do to over come this.

Any help would be appreciated.

Thanks in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You don't need to specify a sheet if you want to reference the cells on the active sheet. If you are clicking on a checkbox and its code runs, then the sheet the checkbox is on is the active sheet.

I think this should work for your situation...
Code:
Private Sub CheckBox1_Click()

    If CheckBox1.Value Then Range("B4").Cut Destination:=Range("D4")
    
End Sub
 
Upvote 0
Thanks for that, works a treat when making a new sheet from the template.

The only issue I have now is I get a #ref error further along my spreadsheet as cell (I4) =D4-H4. (So i can work out what is still left in stock after allocating it to a customer)


I tried to combine both what you have shown me and what I was using previously but I am getting a debug when clicked.

It is probably something fairly simple that I am missing.

Again help would be appreciated.

This is what I have come up with

Code:
Private Sub CheckBox1_Click()

    If CheckBox1.Value Then Range("B4").Copy .Range("D4")
            .Range("B4").ClearContents
            
End Sub
 
Upvote 0
You don't need the periods in front of the Range statments. Those are only needed when used with a With statement. Remove the red periods.
Code:
Private Sub CheckBox1_Click()

    If CheckBox1.Value Then Range("B4").Copy [COLOR="Red"].[/COLOR]Range("D4")
            [COLOR="Red"].[/COLOR]Range("B4").ClearContents
            
End Sub
 
Upvote 0
You don't need the periods in front of the Range statments. Those are only needed when used with a With statement. Remove the red periods.
Code:
Private Sub CheckBox1_Click()

    If CheckBox1.Value Then Range("B4").Copy [COLOR="Red"].[/COLOR]Range("D4")
            [COLOR="Red"].[/COLOR]Range("B4").ClearContents
            
End Sub

Thanks for that AlphaFrog.

Works a treat.

Cheers
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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