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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
How about:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  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
 
Upvote 0
How about:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  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
[/QUOTE

Thanks for Quick Reply, I tried but code not working auto-insert stopped working.
 
Upvote 0
You put this in a module and run it

VBA Code:
sub test()
Application.EnableEvents = True
end sub

Try again
 
Upvote 0
You put this in a module and run it

VBA Code:
sub test()
Application.EnableEvents = True
end sub

Try again

Sorry, I think I am losing you here.
this is the only VBA code in the entire workbook and in the worksheet, there is no conditional formatting.
 
Upvote 0
Thanks for Quick Reply, I tried but code not working auto-insert stopped working.

Sorry, I think I am losing you here.
this is the only VBA code in the entire workbook and in the worksheet, there is no conditional formatting.
If the macro does not work, maybe the events are off, the "Application.EnableEvents = True" instruction is to activate the events. This has nothing to do with formats.

Let's start again.

If you write the word "Done" in cell A2, what do you need?
Do you want the word "Done" to be replaced by the date and the user?
Or what do you need?
 
Upvote 0
Yes ,i want only "done" to be replaced by Username and date ,but for all other words no replacement required .

That makes the code.
You must replace your old code with the new one. Be sure to put the code on the sheet where you write the word "Done"

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  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

To ensure that the events are active, please put the following code in a module and run it. Then you return to the sheet and put the word "Done" in cell B2.

VBA Code:
sub test()
Application.EnableEvents = True
end sub
 
Upvote 0
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

 
Upvote 0

Forum statistics

Threads
1,215,184
Messages
6,123,533
Members
449,106
Latest member
techog

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