1

I'm using a Datepicker solution presented here Formatting MM/DD/YYYY dates in textbox in VBA

I can run it from a Sub, but is it possible to run it from clicking on specific cells?

Community
  • 1
  • 1
miguelmpn
  • 1,859
  • 1
  • 19
  • 25

1 Answers1

1

You can use the Worksheet_BeforeDoubleClick event on your worksheet and only fire the code when a specific cell (or cells) are double-clicked.

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

If Target.Address = "$C$2" Then UserForm1.Show `change to desired cell address and the name of your userform

End Sub

this code should be placed in the Worksheet module

Here is the documentation for the events https://msdn.microsoft.com/en-us/library/office/dn301178.aspx

miguelmpn
  • 1,859
  • 1
  • 19
  • 25
Scott Holtzman
  • 27,099
  • 5
  • 37
  • 72
  • Where do I enable the event? – miguelmpn Mar 18 '16 at 14:22
  • 1
    just place the code in the `Worksheet` module for the sheet you want it to work with (as opposed to a standard module). then, double click on the desire cell and it will fire. – Scott Holtzman Mar 18 '16 at 14:55
  • Thanks, I was placing it on "ThisBook" (I translated it because my office is Portuguese EsteLivro), I changed it and it works – miguelmpn Mar 18 '16 at 15:08
  • 1
    I added the documentation for the events on your answer, so It becomes more complete for those like me who didn't know about them :) – miguelmpn Mar 18 '16 at 15:10