VBA Date stamp from list validation dropdown

Jabberwokki

New Member
Joined
Dec 2, 2020
Messages
33
Office Version
  1. 2010
Platform
  1. Windows
Hi there

I'm using the following code to auto populate dates in various cells based on a selection from a list validation drop down box. For some reason the VBA is also adding Hours, Minutes and Seconds to the resulting value. I can't seem to get just a date regardless of the .NumberFormat = "dd/mm/yyy"

Any advice please?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim Cols As Long

' Auto populate status dates for 7 column setup

If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("N2:N1000")) Is Nothing Then
With Target
If .Value = "" Then Exit Sub
Select Case .Value
Case "backlog": Cols = 1
Case "ip": Cols = 2
Case "blocked": Cols = 4
Case "unblocked": Cols = 5
Case "comp": Cols = 6
Case "nr"
Cols = 1
If .Offset(0, 2).Value = "" Then
.Offset(0, 2).NumberFormat = "dd/mm/yyyy"
.Offset(0, 2).Locked = True
.Offset(0, 2).Value = Now
End If
If .Offset(0, 6).Value = "" Then
.Offset(0, 6).NumberFormat = "dd/mm/yyyy"
.Offset(0, 6).Locked = True
.Offset(0, 6).Value = Now
End If
End Select
If .Offset(0, Cols).Value = "" Then
.Offset(0, Cols).NumberFormat = "dd/mm/yyyy"
.Offset(0, Cols).Locked = True
.Offset(0, Cols).Value = Now
End If
End With
End If
End Sub


Many thanks in advance

Regards

Dominic
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,214,393
Messages
6,119,261
Members
448,880
Latest member
aveternik

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