Programming a checkbox in Excel

  • Thread starter Thread starter FurlongL
  • Start date Start date
F

FurlongL

Hello, I am very unfamiliar with programming VB and Macros in excel.
Here is the situation.

I would like to have a check or an "X" appear in a cell when it is
double clicked.

Can someone please help me with that? Thank you!

Lauren
 
right click on the sheet tab. Select View code. In the left dropdown at the
top of the module select Worksheet and on the right dropdown select
BeforeDoubleclick.

this will put in a code declaration for the Beforedoubleclick event.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

End Sub

This event will fire whenever the sheet is double clicked, before the normal
action of the double click is executed. The cancel argument allows you to
cance that normal action. Now you need to add code to perform the function
you want whenever the cell triggering the event (held as a reference in the
target variable) is the cell you are interested in. For example for cell F9
to have this functionality

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Target.Address = "$F$9" Then
Cancel = True
Target.Font.ColorIndex = 3
If Trim(LCase(Target.Value)) = "x" Then
Target.ClearContents
Else
Target.Value = "X"
End If
End If
End Sub


Make sure you only have one BeforeDoubleClick event in your sheet module.
 

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

Back
Top