Change Date entered to 1st of the month

theheed

New Member
Joined
Aug 20, 2008
Messages
25
Been trying a few methods to either use validation or VB to either force or convert when entered a date to the 1st

I thought about using Datepart to de-construct then reconstruct but this is a bit messy.

i.e. User enters 02/02/11, it changes to 01/02/11

The date column is V for reference

Any ideas??
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Here's an example:

Code:
Sub Test()
    Dim D As Date
    D = DateValue("02/01/2011")
    MsgBox D
    D = DateSerial(Year(D), Month(D), 1)
    MsgBox D
End Sub
 
Upvote 0
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 22 And IsDate(Target.Value) Then
    Application.EnableEvents = False
    Target.Value = DateSerial(Year(Target.Value), Month(Target.Value), 1)
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Hi there,

Try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
        If Not Intersect(Target, Range("V1")) Is Nothing Then
            Target.Value = Target.Value - Day(Target.Value) + 1
        End If
End Sub

Change If Not Intersect(Target, Range("V1")) to the Range you want.
 
Upvote 0
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 22 And IsDate(Target.Value) Then
    Application.EnableEvents = False
    Target.Value = DateSerial(Year(Target.Value), Month(Target.Value), 1)
    Application.EnableEvents = True
End If
End Sub

Works a treat, it is a lot neater than I would have managed
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

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