username and stamp

MMM_84

New Member
Joined
Jan 13, 2021
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a code for username and time stamp as follows, but it doesn't work, as I have another code on the same spreadsheet, which is also "worksheet change..." would you please help?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    If Not Intersect(Target, Me.Range("Am1:Am2000")) Is Nothing Then
        For Each cell In Intersect(Target, Me.Range("Am1:Am2000"))
            If cell.Value <> "" Then
                Me.Cells(cell.Row, "As").Value = Now()
                Me.Cells(cell.Row, "At").Value = Application.UserName
                              
            Else
                Me.Cells(cell.Row, "As").ClearContents
                Me.Cells(cell.Row, "At").ClearContents
                          
            End If
        Next cell
    End If
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
What is the other code that you need this integrated into?
 
Upvote 0
What is the other code that you need this integrated into?
another one is as follow

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("T:T,W;W")) Is Nothing Or Target.Row = 1 Then Exit Sub
Application.EnableEvents = False
Select Case Target.Column
Case Is = 20
Cells(Target.Row, Target.Column + 1).Value = Evaluate("=vlookup(" & Target.Address & ", Sheet2!A:C,2)")
Cells(Target.Row, Target.Column + 2).Value = Evaluate("=offset(" & Target.Address & ",0,1)*10")
Case Is = 23
Cells(Target.Row, Target.Column + 1).Value = Evaluate("=" & Target.Address & "*3")
Case Else
MsgBox "Error!"
End Select
Application.EnableEvents = True
End Sub
 
Upvote 0
You could do something like this, though I would probably make the second code you posted into a loop like the first one:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   On Error GoTo err_handle
   Dim cell As Range
   If Not Intersect(Target, Me.Range("Am1:Am2000")) Is Nothing Then
   
      Application.EnableEvents = False ' turning this off prevents changes made by this code from triggering the change event again
      
      For Each cell In Intersect(Target, Me.Range("Am1:Am2000"))
      
         If cell.Value <> "" Then
            Me.Cells(cell.Row, "As").Value = Now()
            Me.Cells(cell.Row, "At").Value = Application.UserName
         Else
            Me.Cells(cell.Row, "As").ClearContents
            Me.Cells(cell.Row, "At").ClearContents
         End If
         
      Next cell
      
   End If
   
   If Not Intersect(Target, Range("T:T,W;W")) Is Nothing And Target.Row > 1 Then
      
      Application.EnableEvents = False
      Select Case Target.Column
         Case Is = 20
            Cells(Target.Row, Target.Column + 1).Value = Evaluate("=vlookup(" & Target.Address & ", Sheet2!A:C,2)")
            Cells(Target.Row, Target.Column + 2).Value = Evaluate("=offset(" & Target.Address & ",0,1)*10")
         Case Is = 23
            Cells(Target.Row, Target.Column + 1).Value = Evaluate("=" & Target.Address & "*3")
         Case Else
            MsgBox "Error!"
      End Select
   End If
   
clean_up:
   Application.EnableEvents = True
   Exit Sub
   
err_handle:
   MsgBox Err.Description
   Resume clean_up
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,933
Messages
6,175,473
Members
452,646
Latest member
tudou

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