Button to add override date

richardcdahlgren

Board Regular
Joined
Oct 16, 2008
Messages
81
I need a button so when clicked it will open an input box where it says "Enter Date Below" and then user can enter the date and it will paste the date in cell G2. I know it isn't extremely complicated, but my VBA brain is on vacation this week.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,
Place an ActiveX CommandButton on your worksheet & then add this code to the sheets code page & see if does what you want

VBA Code:
Private Sub CommandButton1_Click()
    Dim Entry As Variant
    
    Do
        Entry = InputBox("Enter Date Below", "Enter Date")
        'cancel pressed
        If StrPtr(Entry) = 0 Then Exit Sub
    Loop Until IsDate(Entry)

    Me.Range("G2").Value = DateValue(Entry)
End Sub

Dave
 
Upvote 0
Solution
Upvote 0
I used the active X with no issues so far. I will follow the link to learn more about the difference between the two. Thank you both for the quick replies!!
 
Upvote 0
I used the active X with no issues so far. I will follow the link to learn more about the difference between the two. Thank you both for the quick replies!!
There is nothing wrong with using it, just be aware of the differences and potential issues, especially if you intend to share it with other users or run it on other systems.
Some Virus checking programs may identify/flag it.
 
Upvote 0
I used the active X with no issues so far. I will follow the link to learn more about the difference between the two. Thank you both for the quick replies!!

Me too, developed many systems using ActiveX with no real issues but always useful to be aware of potential problems. You can if wanted / needed, make code a procedure in standard module and Assign a Forms button to it.

I omitted to include displaying the existing date in InputBox & if needed then use update code

VBA Code:
Private Sub CommandButton1_Click()
    Dim Entry As Variant
    Do
        Entry = InputBox("Enter Date Below", "Enter Date", Me.Range("G2").Text)
        'cancel pressed
        If StrPtr(Entry) = 0 Then Exit Sub
    Loop Until IsDate(Entry)

    Me.Range("G2").Value = DateValue(Entry)
End Sub


Glad we could help & appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top