Dynamically assign macro

J

John Smith

Hi again
Select that checkbox and in the name box above cell A1 give it a name.I called
it "stock" in the macro. You need to change it to your choice.
This way it will be unique. then this will delete all but that one.

Sub saveonebox()
Dim myCBX As CheckBox
    For Each myCBX In ActiveSheet.CheckBoxes
       If Not myCBX.Name = "stock" Then
        myCBX.Delete
        End If
    Next myCBX
End Sub






How would I protect that single cell, since I need to delete
everything else on the page every time it gets used?- Hide quoted text -

- Show quoted text -

I can't seem to get it to work - it still deletes the checkbox in A1.
 
C

Cimjet

This is a link to a sample file that you can play with.
http://cjoint.com/?BAsd5Lr4hYe
Cimjet
Hi again
Select that checkbox and in the name box above cell A1 give it a name.I called
it "stock" in the macro. You need to change it to your choice.
This way it will be unique. then this will delete all but that one.

Sub saveonebox()
Dim myCBX As CheckBox
For Each myCBX In ActiveSheet.CheckBoxes
If Not myCBX.Name = "stock" Then
myCBX.Delete
End If
Next myCBX
End Sub






How would I protect that single cell, since I need to delete
everything else on the page every time it gets used?- Hide quoted text -

- Show quoted text -

I can't seem to get it to work - it still deletes the checkbox in A1.
 
J

John Smith

Hi again
Select that checkbox and in the name box above cell A1 give it a name.I called
it "stock" in the macro. You need to change it to your choice.
This way it will be unique. then this will delete all but that one.

Sub saveonebox()
Dim myCBX As CheckBox
    For Each myCBX In ActiveSheet.CheckBoxes
       If Not myCBX.Name = "stock" Then
        myCBX.Delete
        End If
    Next myCBX
End Sub






How would I protect that single cell, since I need to delete
everything else on the page every time it gets used?- Hide quoted text -

- Show quoted text -

Eureka! I got it. Thanks Cimjet.
 
C

Cimjet

Great, glad you got it working
Good night
Cimjet
Hi again
Select that checkbox and in the name box above cell A1 give it a name.I called
it "stock" in the macro. You need to change it to your choice.
This way it will be unique. then this will delete all but that one.

Sub saveonebox()
Dim myCBX As CheckBox
For Each myCBX In ActiveSheet.CheckBoxes
If Not myCBX.Name = "stock" Then
myCBX.Delete
End If
Next myCBX
End Sub






How would I protect that single cell, since I need to delete
everything else on the page every time it gets used?- Hide quoted text -

- Show quoted text -

Eureka! I got it. Thanks Cimjet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top