Use change event to change the format of a date

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
784
Office Version
  1. 365
Platform
  1. Windows
Hi


I’m trying to add more to this change event macro
The first part works perfectly. What every text is entered in a cell in column 4 is changed to proper case.
I’m trying to get column 1 and column 2 to change the format when a date is entered.
Column 1 and column will only have dates in them
What I get now is “FALSE”
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 Then
Application.EnableEvents = False
Target.Value = Application.Proper(Target.Value).
Application.EnableEvents = True
End If
If Target.Column = 1 Then
Application.EnableEvents = False
Target.Value = Selection.NumberFormat = "mm/dd/yy"
Application.EnableEvents = True
End If
If Target.Column = 2 Then
Application.EnableEvents = False
Target.Value = Selection.NumberFormat = "mm/dd/yy"
Application.EnableEvents = True
End If
End Sub



mike
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
VBA Code:
Target.NumberFormat = "mm/dd/yy"

although you could combine the bottom 2 into 1 section:
VBA Code:
If Target.Column = 1 or Target.Column = 2 Then
 
Upvote 0
Solution

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

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