Toggle Button help

J

jonco

I want to create 2 toggle buttons.

1.) Toggle button 1: When it is clicked cell C33 contains an "X" in it.
When it is clicked again the "X" goes away and the cell is empty.

2.) Toggle button 2: I want this toggle button to clear out certain cells
(a range) and when it is clicked again to put sample data in that range.

Sounds simple...but I'm having trouble figuring out how to do it.

Thanks for your help!

Jonco
 
D

Dave Peterson

I put two toggle buttons from the Control toolbox toolbar on a worksheet.

I put this in that worksheet's code module:
 
D

Dave Peterson

I put two toggle buttons from the Control toolbox toolbar on a worksheet.

I put this in that worksheet's code module:

Option Explicit
Private Sub ToggleButton1_Click()
If Me.ToggleButton1.Value = True Then
Me.Range("c33").ClearContents
Else
Me.Range("C33").Value = "X"
End If
End Sub

Private Sub ToggleButton2_Click()
Dim myRng As Range
Dim myArea As Range

Set myRng = Me.Range("a3:b9,c12:d18,f19,g1:h3")

If Me.ToggleButton2.Value = True Then
myRng.ClearContents
Else
For Each myArea In myRng.Areas
With myArea
.Formula = "=rand()"
.Value = .Value
End With
Next myArea
End If
End Sub
 

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