Hello, I am using two separate Macros in two separate Excel documents. I need help combining them. The first Macro I am using will automatically add the current users user name, the time, and the date when a user puts information into column A. So if the users puts something into cell A1 then B1 automatically gets filled with their username and C1 gets filled with the time and date.
The second Macro automatically locks cells in columns D through I after the user enters data.
I would like to bring these to Macros together but can not figure it out! Any thoughts or suggestions would be appreciated! Thanks!
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rCell As Range
Dim rChange As Range
On Error GoTo justenditall
Set rChange = Intersect(Target, Range("D:I"))
If Not rChange Is Nothing Then
Application.EnableEvents = False
For Each rCell In rChange
If rCell > "" Then
ActiveSheet.Unprotect Password:="thepassword"
Target.Locked = True
End If
Next
End If
ActiveSheet.Protect Password:="thepassword"
justenditall:
Application.EnableEvents = True
End Sub
-----------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rCell As Range
Dim rChange As Range
On Error GoTo ErrHandler
Set rChange = Intersect(Target, Range("A:A"))
If Not rChange Is Nothing Then
Application.EnableEvents = False
For Each rCell In rChange
If rCell > "" Then
rCell.Offset(0, 1).Value = UserName()
rCell.Offset(0, 2).Value = Date & " " & Time()
Else
rCell.Offset(0, 1).Clear
End If
Next
End If
ExitHandler:
Set rCell = Nothing
Set rChange = Nothing
Application.EnableEvents = True
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
Public Function UserName()
UserName = Environ$("UserName")
End Function
Bookmarks