"Toggle Switch" help needed

L

Les Stout

Hi all, this is probably so easy but it is eluding me !!

I need to make an edit button that inserts a 1 in A1 and the caption
then changes to "DONE" and when clicked again it removes the 1 from A1
and the caption then changes back to "EDIT"


Best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
 
N

Nigel

Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Done" Then
CommandButton1.Caption = "Edit"
Range("A1") = ""
Else
CommandButton1.Caption = "Done"
Range("A1") = 1
End If
End Sub
 
R

Rick Rothstein \(MVP - VB\)

Maybe this?

Private Sub CommandButton1_Click()
With CommandButton1
If .Caption = "DONE" Then
ActiveSheet.Range("A1").Value = ""
.Caption = "EDIT"
Else
ActiveSheet.Range("A1").Value = "1"
.Caption = "DONE"
End If
End With
End Sub

Rick
 
M

Mike H

les,

I'm not sure what you mean by an 'Edit Button' so this is a 'Toggle Button'
from the Control toolbox.

Set the caption to 'Edit' right click the button, view code and paste this in

Private Sub ToggleButton1_Click()
With ToggleButton1
If .Caption = "Edit" Then
Range("A1").Value = 1
.Caption = "Done"
Else
Range("A1").Value = ""
.Caption = "Edit"
End If
End With
End Sub


Mike
 
R

Rick Rothstein \(MVP - VB\)

I would **not** use the following in production code... I'm posting it more
to get the reader to see there are ways to "think outside the box" when it
comes to coding (and, also, as an exercise for the reader to decipher why it
works<g>)...

Private Sub CommandButton1_Click()
Range("A1").Value = String(1 - Val(Range("A1").Value), "1")
CommandButton1.Caption = Split("EDIT DONE")(Val(Range("A1").Value))
End Sub

Rick
 

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