stewart1
Board Regular
- Joined
- Feb 25, 2010
- Messages
- 66
Good evening or morning to all.
Well at the moment I have about ten tabs on Firefox open and a raging headache!
I have just found out (shows how green I am) that I cannot have "two" worksheet_changes going on.
I have put "end ifs" and Lord knows what in to try and run these two events, but at best one works and the other doesn't or I get errors "End If without "Block If" and it's all going a bit wrong, and my wife keeps looking at me like I'm a bit weird because I am talking to myself saying "please work".
So, I have these two bits of code first one here locks the cell on the chosen columns after the user presses "yes" (columns L,M and N have a popcal called, user enters a date and the choice "yes" locks it).
This is great but I needed this code below to work as well:
This was some code I found which allowed the date to be entered and the date cell locked after data was put into column D.
So can I get these to work alongside each other and if so what joins them please. Can I use this
a second time within the worksheet independantly of that one so I could have code for example entry in column B trigger date entry in column A
If it does make a difference I do have a workbook code for locking those columns but I would have thought that it wouldn't interfere with any others.
If anyone can help tell me what the "link" is I would be grateful.
i hope I have explained myself OK.
Thanks for looking.
Stewart
Well at the moment I have about ten tabs on Firefox open and a raging headache!
I have just found out (shows how green I am) that I cannot have "two" worksheet_changes going on.
I have put "end ifs" and Lord knows what in to try and run these two events, but at best one works and the other doesn't or I get errors "End If without "Block If" and it's all going a bit wrong, and my wife keeps looking at me like I'm a bit weird because I am talking to myself saying "please work".
So, I have these two bits of code first one here locks the cell on the chosen columns after the user presses "yes" (columns L,M and N have a popcal called, user enters a date and the choice "yes" locks it).
Code:
Private Sub Worksheet_Change(ByVal Target As Range)Dim Ans As VariantIf Application.Intersect(Target, Range("L2:L10000, M2:M10000, N2:N10000")) Is Nothing Then Exit Sub
Ans = MsgBox("Are you sure you want to enter " & Target.Value, vbQuestion + vbYesNo, "Confirm Entry")
If Ans = vbYes Then Target.Locked = True
End Sub
This is great but I needed this code below to work as well:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)Dim Rng As Range
If Target.Count > 1 Then Exit Sub
Set Rng = Range("D1:D10000")
' Only look at that range
If Intersect(Target, Rng) Is Nothing Then Exit Sub
ActiveSheet.Unprotect ""
If Target.Offset(, 4) = "" Then Target.Offset(, 4) = Date
ActiveSheet.Protect ""
This was some code I found which allowed the date to be entered and the date cell locked after data was put into column D.
So can I get these to work alongside each other and if so what joins them please. Can I use this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)Dim Rng As Range
If Target.Count > 1 Then Exit Sub
Set Rng = Range("D1:D10000")
' Only look at that range
If Intersect(Target, Rng) Is Nothing Then Exit Sub
ActiveSheet.Unprotect ""
If Target.Offset(, 4) = "" Then Target.Offset(, 4) = Date
ActiveSheet.Protect ""
a second time within the worksheet independantly of that one so I could have code for example entry in column B trigger date entry in column A
If it does make a difference I do have a workbook code for locking those columns but I would have thought that it wouldn't interfere with any others.
If anyone can help tell me what the "link" is I would be grateful.
i hope I have explained myself OK.
Thanks for looking.
Stewart