I have a spreadsheet that I want to record who made a change, and then send an automatic email to a person if the user who made the change is # a certain criteria.
To write the user to a cell, I have used this code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function UserNameWindows() As String
Dim lngLen As Long
Dim strBuffer As String
Const dhcMaxUserName = 255
strBuffer = Space(dhcMaxUserName)
lngLen = dhcMaxUserName
If CBool(GetUserName(strBuffer, lngLen)) Then
UserNameWindows = Left$(strBuffer, lngLen - 1)
Else
UserNameWindows = ""
End If
End Function
To Use that in my spreadsheet and then email information, I have tried to use this code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("I3:I102"), Target) Is Nothing Then
Range("M1").Select
ActiveCell.FormulaR1C1 = "=USERNAMEWINDOWS()"
Range("M1").Select
Selection.Copy
Range("M3:M102").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Call Mail_Ardmore_changes(Target)
End If
If Not Application.Intersect(Range("I3:I102"), Target) Is Nothing Then
If (Target.Value) & rng.Offset(0, 4) # "MANOPAME" Then
Call Mail_Ardmore_changes_blind(Target)
Range("M3:M102").Select
Selection.ClearContents
Range("d1").Select
End If
End If
End Sub
I am getting hung up on [If (Target.Value) & rng.Offset(0, 4) # "MANOPAME" Then]. The intent here is that if the 4th cell to the right of the change says anything other than MANOPAME, I want the macro to then call the Mail_Ardmore_changes_blind macro and send the auto email to alert than an unauthorized person made this change.
Could someone help me with the proper code? Thanks so much, Pam
Bookmarks