Automatically enter user name and date

longwayne

Board Regular
Joined
Feb 18, 2014
Messages
52
Office Version
  1. 2019
I making a new daily log sheet for our team. As a team member starts to type in his/her summary, I would like excel to automatically enter the time and date {column A & C) also, the user name of the computer user (column B). There are 5 to 8 team members that share two laptops, but we all have our own user
 

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.
What range (column) will they be typing into?

What if they type into a range that already has columns A-C populated (i.e. they are editing an existing record)?
Do you want columns A-C refreshed with the new data, or leave the original?
 
Upvote 0
I making a new daily log sheet for our team. As a team member starts to type in his/her summary, I would like excel to automatically enter the time and date (column A & C) also, the user name of the computer user (column B). There are 5 to 8 team members that share the laptops, but we all have our own user ID.

[A] [C] [D]
DATE Operator Time Summary
Monday, April 20, 2020 WLONGHURST 10:00 PM Wlong sighed in, Influent PH
is 4.46, Caustic is at 6.31, Effluent
conductivity is 670, Influent
turbitiy is 12.5 Effluent Cl2 is 0.25.
Monday, April 20, 2020 WLONGHURST 11:00 PM Tank Alum pump #1. RO Break
Tank By-pass pump #2
Monday, April 20, 2020 WLONGHURST 11:30 AM Filled out and logged Waste to
Energy Shift change Sheet
Monday, April 20, 2020 WLONGHURST 11:45 PM Checked inf. Cl2-0.68ppm, Clarifier
Efl.Cl2- 0.04ppm

What range (column) will they be typing into?

What if they type into a range that already has columns A-C populated (i.e. they are editing an existing record)?
Do you want columns A-C refreshed with the new data, or leave the original?
 

Attachments

  • 2022-04-26 07_38_26-.png
    2022-04-26 07_38_26-.png
    107.2 KB · Views: 7
Upvote 0
What range (column) will they be typing into?

What if they type into a range that already has columns A-C populated (i.e. they are editing an existing record)?
Do you want columns A-C refreshed with the new data, or leave the original?
Each operator will start a new line by entering a note in the summery column.
 
Upvote 0
Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the resulting VB Editor window:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if multiple cells updated at once (i.e. row deleted)
    If Target.CountLarge > 1 Then Exit Sub
    
'   Only run if column D after row 4 updated
    If Target.Column = 4 And Target.Row > 4 Then
        Application.EnableEvents = False
'       Update column A with current date
        Target.Offset(0, -3).Value = Date
'       Update column B with user
        Target.Offset(0, -2).Value = Environ("username")
'       Update column C with time
        Target.Offset(0, -1).Value = Now()
        Application.EnableEvents = True
    End If

End Sub
As long as VBA is enable, this will automatically populate columns A-C with the information you want whenever an entry is made in column D below row 4.
 
Upvote 0
Solution
Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the resulting VB Editor window:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if multiple cells updated at once (i.e. row deleted)
    If Target.CountLarge > 1 Then Exit Sub
   
'   Only run if column D after row 4 updated
    If Target.Column = 4 And Target.Row > 4 Then
        Application.EnableEvents = False
'       Update column A with current date
        Target.Offset(0, -3).Value = Date
'       Update column B with user
        Target.Offset(0, -2).Value = Environ("username")
'       Update column C with time
        Target.Offset(0, -1).Value = Now()
        Application.EnableEvents = True
    End If

End Sub
As long as VBA is enable, this will automatically populate columns A-C with the information you want whenever an entry is made in column D below row 4.
I "saved as" a macro workbook accepted macro and still received a syntax error.
 

Attachments

  • Syntax error.png
    Syntax error.png
    38.3 KB · Views: 7
Upvote 0
Your copy/paste attempt missed the "b" at the end of "End Sub".
(Look at the code I posted versus the code you posted!).
 
Upvote 0
My apology, but I have accepted the VBA in options, and pasted correctly. the syntax error is gone. But, the cells A:C still do not populate with the time and user name.
 
Upvote 0
My apology, but I have accepted the VBA in options, and pasted correctly. the syntax error is gone. But, the cells A:C still do not populate with the time and user name.
Have you enabled VBA code to run?
Is column B being populated?
What is the name of the module where you have placed this VBA code?
 
Upvote 0
Have you enabled VBA code to run?
Is column B being populated?
What is the name of the module where you have placed this VBA code?
I went to options, Trust center, Marcos, Enable VBA.
I went to tabs, view code, pasted your code
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,925
Members
449,094
Latest member
teemeren

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