Message box to change workbook date

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
573
Office Version
  1. 365
Platform
  1. Windows
I have a workbook that requires the date to be changed on the input tab (which then updates the date fields on the other worksheets). I would like to have a mesage box pop upp when the workbook is opened asking if I want to change the date. If the answer is yese I would like anouther box to pop up letting me enter a date that will populate cell B6 on the input worksheet. If the answer is no then it would leave things as they are.

Any help with this is greatly appreciatated.

Thanks
Mark
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You want to add VBA code to the Workbook_Open event, which automatically runs on a VBA enabled workbook when the file is opened. If you are unfamiliar with Event Codes, and where to enter the VBA, have a look here:
http://www.cpearson.com/excel/Events.aspx

The VBA code will look something like this:
Code:
Private Sub Workbook_Open()
    Dim MyPrompt1
    Dim MyInput1 As Date
 
    Sheets("Input").Activate
    MyPrompt1 = MsgBox("The current workbook date is " & Range("B6") & vbCrLf & "Would you like to change it?", vbYesNo)
    If MyPrompt1 = vbYes Then
        MyInput1 = InputBox("Enter new workbook date")
        Range("B6") = MyInput1
    End If
 
End Sub
 
Upvote 0
Try this: right click the Excel logo just to the left of File on the menu bar, select View Code and paste in

Code:
Private Sub Workbook_Open()
Dim a As VbMsgBoxResult, b As String
a = MsgBox("Do you want to update the date?", vbYesNo + vbQuestion)
If a = vbNo Then Exit Sub
b = InputBox("Enter the new date")
Sheets("Input").Range("B6").Value = DateValue(b)
End Sub

Save, close and re-open the workbook.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,400
Members
448,893
Latest member
AtariBaby

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