Enio Goncalves
New Member
- Joined
- Nov 4, 2014
- Messages
- 5
Hello.
I'm new to VBA language. I have 2 Worksheet_Change routines that work fine by themselves,but i need to put them both in the same sheet.
I know that there can be only one per sheet, so I guess that the only way is to bind both routines into one, but I don't know how...
First one (timestamps cell in Column "E" when cell in column "H" is filled)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 8 Then
Cells(Target.Row, 5).Value = Date + Time
Application.EnableEvents = True
End If
End Sub
Second one (locks intire row - except a few cells - when cell in column "C" is filled)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then '3=column C
If Target.Value = "" Then
Me.Unprotect Password:="xxx"
Range(Target.Offset(0, 1), Target.Offset(0, 76)).Locked = False
'leave these locked:
Range("D" & Target.Row).Locked = True
Range("E" & Target.Row).Locked = True
Range("P" & Target.Row).Locked = True
Range("AA" & Target.Row).Locked = True
Range("AD" & Target.Row).Locked = True
Range("AX" & Target.Row).Locked = True
Me.Protect Password:="xxx", AllowFiltering:=True
Else
Me.Unprotect Password:="xxx"
Range(Target.Offset(0, 1), Target.Offset(0, 76)).Locked = True
'dont block these:
Range("X" & Target.Row).Locked = False
Range("BA" & Target.Row).Locked = False
Range("BC" & Target.Row).Locked = False
Range("BE" & Target.Row).Locked = False
Range("BG" & Target.Row).Locked = False
Range("BI" & Target.Row).Locked = False
Range("BK" & Target.Row).Locked = False
Range("BP" & Target.Row).Locked = False
Me.Protect Password:="xxx", DrawingObjects:=False, Contents:=True, Scenarios:=True _
, AllowFiltering:=True
End If
End Sub
I apreciate all the help you can give me
I'm new to VBA language. I have 2 Worksheet_Change routines that work fine by themselves,but i need to put them both in the same sheet.
I know that there can be only one per sheet, so I guess that the only way is to bind both routines into one, but I don't know how...
First one (timestamps cell in Column "E" when cell in column "H" is filled)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 8 Then
Cells(Target.Row, 5).Value = Date + Time
Application.EnableEvents = True
End If
End Sub
Second one (locks intire row - except a few cells - when cell in column "C" is filled)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then '3=column C
If Target.Value = "" Then
Me.Unprotect Password:="xxx"
Range(Target.Offset(0, 1), Target.Offset(0, 76)).Locked = False
'leave these locked:
Range("D" & Target.Row).Locked = True
Range("E" & Target.Row).Locked = True
Range("P" & Target.Row).Locked = True
Range("AA" & Target.Row).Locked = True
Range("AD" & Target.Row).Locked = True
Range("AX" & Target.Row).Locked = True
Me.Protect Password:="xxx", AllowFiltering:=True
Else
Me.Unprotect Password:="xxx"
Range(Target.Offset(0, 1), Target.Offset(0, 76)).Locked = True
'dont block these:
Range("X" & Target.Row).Locked = False
Range("BA" & Target.Row).Locked = False
Range("BC" & Target.Row).Locked = False
Range("BE" & Target.Row).Locked = False
Range("BG" & Target.Row).Locked = False
Range("BI" & Target.Row).Locked = False
Range("BK" & Target.Row).Locked = False
Range("BP" & Target.Row).Locked = False
Me.Protect Password:="xxx", DrawingObjects:=False, Contents:=True, Scenarios:=True _
, AllowFiltering:=True
End If
End Sub
I apreciate all the help you can give me