Getting Static Username and time.

Newbie212

New Member
Joined
Oct 15, 2018
Messages
16
Office Version
  1. 2010
Platform
  1. Windows
Hello Excel/VBA Masters!

I got a table and with info that needs to be verified by employee. Next to each row of information there is Data Validation list (Verified / Not Verified). I got formulas down that show the username and time+date of verification, than i i lock the cells if there is any input in them, using this:

HTML:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xRg As Range
    On Error Resume Next
    Set xRg = Intersect(Range("J2:L102"), Target)
    If xRg Is Nothing Then Exit Sub
    Target.Worksheet.Unprotect Password:="123" 
   xRg.Locked = True 
   Target.Worksheet.Protect Password:="123"    
End Sub

Problem is that, as it turns out both Username() and Now() functions are dynamic and show the current time + user.

Is it possible to get Static Username() + Now() in a cell(Or 2 separate cells, doesn't matter much), and than lock them?


Thank you for the help! :)
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
What column is the drop-down in & what columns need the username & date
 
Upvote 0
There are 4 locked columns.
J - Is conditional formatting that gets a green check mark if Verified is selected.
K - is the Data Validation column.
L - Username. I get username from:

HTML:
Public Function UserName()  
  UserName = Environ$("UserName")
End Function

M - is Date/Time with Now() function.

PS. Now that i look i think i made a small typo in my first post. The range should be Set xRg = Intersect(Range("J2:M102"), Target).
 
Last edited:
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("K2:K102")) Is Nothing Then
      If Target.Value = "Verified" Then
         Application.EnableEvents = False
         Me.Unprotect Password:="123"
         Target.Offset(, 1).Resize(, 2).Value = Array(Environ$("Username"), Now)
         Target.Offset(, -1).Resize(, 4).Locked = True
         Me.Protect Password:="123"
         Application.EnableEvents = True
      End If
   End If
End Sub
 
Upvote 0
Worked from the first try! :)

[FONT=&quot]You’re the best. Thanks so much.[/FONT]
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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