Loop my Change Event

WaterSkiExcel

New Member
Joined
Mar 11, 2014
Messages
9
I'm new to the VBA side of excel. I need to auto-populate the "date" and "username" into columns A and B when a value is typed into column G. I'm able to do this for one line (something is typed in G13, then A13 and B13 populate) using this code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$13" Then
Range("A13").Value = Date
Range("B13").Value = UCase(Application.UserName)
End If
End Sub

How do I make this loop so anytime a value is typed into a cell in column G the corresponding cells in column A and B auto-populate?

Thanks
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Something like
Code:
With Target.Cells(1, 1)
    If .Column = 7 Then
        With .EntireRow
            .Range("A1") = Date
            .Range("B1") = Application.UserName
        End With
    End If
End With
 
Upvote 0
Hi,

Try the following - note the disable events
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Column = 7 Then
        With Workbooks(ThisWorkbook.Name).Worksheets("Sheet1")
        Application.EnableEvents = False
            Target.Offset(0, -6) = Date
            Target.Offset(0, -5) = UCase(Application.UserName)
            Application.EnableEvents = True
        End With
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

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