restrict cell format in a given column

TG2812

Board Regular
Joined
Apr 15, 2015
Messages
180
Hello,

I'm trying to come up with a small macro allowing to restrict the user input to a given date format in column B. If it is not a date, then content is cleared and a pop up message appear to alert the user. Ultimately all date format should align to mm/dd/yyyy (the macro could auto correct wrong date input). Any idea how to build such code?

I initially wanted to insert Microsoft date and time picker control but I do not have the right version of excel installed (using 64 bits)..add-ins are also not a solution as it would require the other users to have it installed on their PCs. Hence why the macro is a viable alternative in my case.

Thank you in advance for your help .
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
@jasonb75 thank you for the prompt reply. I tried data validation but I cannot apply the formula to a specific column only (or at least I haven't found a way to do it).

=AND(ISNUMBER(B2),LEFT(CELL("format",B2),1)="D")

Alternatively, i came up with this macro but the worksheet event is not correct I thin. For example when i enter text value and hit enter, nothing happens.

Private Sub Worksheet_Activate()
If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
Set c = ActiveCell
If c.Value <> "" And Not IsDate(c) Then
c.ClearContents
MsgBox "Only a date format is permitted in this cell."
End If
End If
End Sub
 
Upvote 0
Don't use a formula for validation, just set a min and max date range with the correct format already applied to the cells, then protect the sheet.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,861
Members
449,052
Latest member
Fuddy_Duddy

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