Insert Microsoft user's name into cell

DaRTH KiRo

New Member
Joined
Jan 24, 2018
Messages
39
Office Version
  1. 2016
Platform
  1. Windows
Is there a code or formula I can put in place that will enter the Microsoft user's name or email, who is in the excel sheet, in column N when text is entered in column A?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Column = 1 Then
      Target.Offset(, 13).Value = Environ("Username")
   End If
End Sub
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Column = 1 Then
      Target.Offset(, 13).Value = Environ("Username")
   End If
End Sub
So I'm not super great at vba, how would I incorporate that code into the below code I already have?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim WorkRng1 As Range
    Dim WorkRng2 As Range
    Dim WorkRng As Range
    Dim Rng As Range
    Dim xOffsetColumn As Integer
    
    Set WorkRng1 = Intersect(Application.ActiveSheet.Range("J:J"), Target)
    Set WorkRng2 = Intersect(Application.ActiveSheet.Range("L:L"), Target)
    
    If Not WorkRng1 Is Nothing Then
        If Not WorkRng2 Is Nothing Then
            Set WorkRng = Application.Union(WorkRng1, WorkRng2)
        Else
            Set WorkRng = WorkRng1
        End If
    Else
        If Not WorkRng2 Is Nothing Then
            Set WorkRng = WorkRng2
        End If
    End If
    
    xOffsetColumn = 1
    
    If Not WorkRng Is Nothing Then
        Application.EnableEvents = False
        For Each Rng In WorkRng
            If Not VBA.IsEmpty(Rng.Value) Then
                Rng.Offset(0, xOffsetColumn).Value = Now
                Rng.Offset(0, xOffsetColumn).NumberFormat = "mm-dd-yyyy, hh:mm:ss"
            Else
                Rng.Offset(0, xOffsetColumn).ClearContents
            End If
        Next
        Application.EnableEvents = True
    End If
    
End Sub
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim WorkRng1 As Range
    Dim WorkRng2 As Range
    Dim WorkRng As Range
    Dim Rng As Range
    Dim xOffsetColumn As Integer
    
    Set WorkRng1 = Intersect(Application.ActiveSheet.Range("J:J"), Target)
    Set WorkRng2 = Intersect(Application.ActiveSheet.Range("L:L"), Target)
    
    If Target.Column = 1 Then
       Target.Offset(, 13).Value = Environ("Username")
    End If

    If Not WorkRng1 Is Nothing Then
        If Not WorkRng2 Is Nothing Then
            Set WorkRng = Application.Union(WorkRng1, WorkRng2)
        Else
            Set WorkRng = WorkRng1
        End If
    Else
        If Not WorkRng2 Is Nothing Then
            Set WorkRng = WorkRng2
        End If
    End If
    
    xOffsetColumn = 1
    
    If Not WorkRng Is Nothing Then
        Application.EnableEvents = False
        For Each Rng In WorkRng
            If Not VBA.IsEmpty(Rng.Value) Then
                Rng.Offset(0, xOffsetColumn).Value = Now
                Rng.Offset(0, xOffsetColumn).NumberFormat = "mm-dd-yyyy, hh:mm:ss"
            Else
                Rng.Offset(0, xOffsetColumn).ClearContents
            End If
        Next
        Application.EnableEvents = True
    End If
    
End Sub
 
Upvote 0
Solution
T
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim WorkRng1 As Range
    Dim WorkRng2 As Range
    Dim WorkRng As Range
    Dim Rng As Range
    Dim xOffsetColumn As Integer
   
    Set WorkRng1 = Intersect(Application.ActiveSheet.Range("J:J"), Target)
    Set WorkRng2 = Intersect(Application.ActiveSheet.Range("L:L"), Target)
   
    If Target.Column = 1 Then
       Target.Offset(, 13).Value = Environ("Username")
    End If

    If Not WorkRng1 Is Nothing Then
        If Not WorkRng2 Is Nothing Then
            Set WorkRng = Application.Union(WorkRng1, WorkRng2)
        Else
            Set WorkRng = WorkRng1
        End If
    Else
        If Not WorkRng2 Is Nothing Then
            Set WorkRng = WorkRng2
        End If
    End If
   
    xOffsetColumn = 1
   
    If Not WorkRng Is Nothing Then
        Application.EnableEvents = False
        For Each Rng In WorkRng
            If Not VBA.IsEmpty(Rng.Value) Then
                Rng.Offset(0, xOffsetColumn).Value = Now
                Rng.Offset(0, xOffsetColumn).NumberFormat = "mm-dd-yyyy, hh:mm:ss"
            Else
                Rng.Offset(0, xOffsetColumn).ClearContents
            End If
        Next
        Application.EnableEvents = True
    End If
   
End Sub
That is amazing, thank you so much!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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