Auto Insert Username and Date Stamp on Specific cell value from Drop-down.

Jeet_Dhillon

New Member
Joined
Jul 13, 2019
Messages
19
Hello Friends,
I am using this code for auto inserting date and username when a cell value is changed.
I need when "Done" is selected from the dropdown list,auto-insert should trigger, but now auto-insert is for all the Values.
Please share some suggestions
thanks.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Handler
If Target.Column = 2 Or Target.Column = 4 Or Target.Column = 6 Or Target.Column = 8 And Target.Value <> "" Then
Application.EnableEvents = False
Target.Offset(0, 0) = Format(Now(), "dd-mm-yy/") & Environ("UserName")
Application.EnableEvents = True
End If
Handler:
End Sub
 
But saying "code won't work" is not enough. It does nothing or sends an error. You can comment

Try this, A message with "Hi" should appear, if it does not appear, it means that your events are not active or the macro is elsewhere, the macro should be in the events of the sheet.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  msgbox "Hi"
  On Error GoTo Handler
  If Target.CountLarge > 1 Then Exit Sub
  If (Target.Column = 2 Or Target.Column = 4 Or Target.Column = 6 Or Target.Column = 8) _
    And LCase(Target.Value) = LCase("Done") Then
    Application.EnableEvents = False
    Target.Value = Format(Now(), "dd-mm-yy/") & Environ("UserName")
    Application.EnableEvents = True
  End If
Handler:
  Application.EnableEvents = True
End Sub

SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.

_______________________________________________________

I share my test file. type "done" in cell B3 and automatically stamp the date and user


Thanks for Help, When I moved the target sheet from an existing workbook, this code is working as required.
then I moved back this sheet to the same workbook, code is still working. Not sure what was wrong.
I appreciate your Patience.
Take care.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Im glad to help you. Thanks for the feedback.
Take care too :biggrin:
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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