Input Boxes and Dates

snoosnoo

New Member
Joined
Apr 14, 2016
Messages
4
Hi, I want the default value of my input box to reference a cell. This cell is also the destination for the data inputted in the input box. I'm running into some issues with the value posted back to the cell.. let me explain exactly

In C2 I have the date 01/04/2016. When I run Sub EnterDate() the default value that appears in the input box is 01/04/2016, which is what I would expect. However when I click OK, essentially writing the date 01/04/2016 back to cell C2, the value in C2 now reads 04/01/2016. I suspect it has something to do with US date writing versus EU date writing (inverting the day and the month) , but really don't know how to solve this issue! Would be grateful for any help :)

Code:
Sub EnterDate()

Dim DataMonth As Variant
Sheets("Instructions").Select
DataMonth = InputBox("Please enter the month for which the data corresponds in MMM YYYY form", "Enter Month", Range("C2"))
Range("C2").Value = DataMonth

End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi,
see if this update to your code does what you want:

Code:
Sub EnterDate()
    Dim DataMonth As Variant
    Dim wsInstructions As Worksheet
    Dim Prompt As String, Default As String
    
    Set wsInstructions = ThisWorkbook.Sheets("Instructions")
    
    Prompt = "Please enter the month for which the data corresponds in MMM YYYY form"
    Default = wsInstructions.Range("C2").Text
    
    Do
        DataMonth = InputBox(Prompt, "Enter Month", Default)
'cancel pressed
        If StrPtr(DataMonth) = 0 Then Exit Sub
    Loop Until IsDate(DataMonth)
    
    wsInstructions.Range("C2").Value = DateValue(DataMonth)
    
End Sub


Dave
 
Upvote 0

Forum statistics

Threads
1,215,230
Messages
6,123,752
Members
449,118
Latest member
kingjet

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