Hi,
Basically, the code asks user to enter the date in format “m/d/yyyy”. If the format is incorrect, it asks the user to enter again until the format is correct. If user clicks the “cancel” button, the macro stops. If the format is correct, then continue to the following procedure (e.g. Range("A1").Value = dt). I declare the variable, use InputBox function and the code for “cancel”, but how can I develop the rest of codes for what I want. Thanks in advance.
Basically, the code asks user to enter the date in format “m/d/yyyy”. If the format is incorrect, it asks the user to enter again until the format is correct. If user clicks the “cancel” button, the macro stops. If the format is correct, then continue to the following procedure (e.g. Range("A1").Value = dt). I declare the variable, use InputBox function and the code for “cancel”, but how can I develop the rest of codes for what I want. Thanks in advance.
Code:
Sub save_as_date()
Dim dt As String
dt = InputBox("enter date in format m/y/yyyy")
If dt = "" Then Exit Sub
Range("A1").Value = dt
end sub