SewerUrchin
New Member
- Joined
- Jan 25, 2005
- Messages
- 24
Most respected forum members:
ray:
Here is a sample of the code I have for locking three cells after the user populates the cells. The problem I'm having is the system either highlights the range specified in line 5 of this code after the code is executed, or if I specify it, I can set the focus to A1. But that isn't what I need. . .
What I want to have the system do is mark where the cursor is by coordinate before the WorksheetChange code executes. (in my code it is variable NowCell) Then I can set the cursor back to the active cell that fired the code and then move the focus one column to the right. In essence, making easier for the person entering data to do it by row. I can't get the syntax of the final statement right and I'm wondering if it has to do with the variable type I'm using for NowCell? I'm also betting that I can't treat a variable like an Excel element, as I have done below. Thoughts? Opinions? Anything is appreciated.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim NowCell As Variant
NowCell = ActiveCell.Address(ReferenceStyle:=xlR1C1)
ActiveSheet.Unprotect Password:="password"
Range("A1:J10").Select
Selection.Locked = False
If ActiveSheet.Range("I4") <> "" Then
ActiveSheet.Range("I4").Locked = True
End If
If ActiveSheet.Range("B4") <> "" Then
ActiveSheet.Range("B4").Locked = True
End If
If ActiveSheet.Range("I6") <> "" Then
ActiveSheet.Range("I6").Locked = True
End If
ActiveSheet.Protect Password:="password"
NowCell.Offset(0, 1).SetFocus
End Sub
Thanks!
Here is a sample of the code I have for locking three cells after the user populates the cells. The problem I'm having is the system either highlights the range specified in line 5 of this code after the code is executed, or if I specify it, I can set the focus to A1. But that isn't what I need. . .
What I want to have the system do is mark where the cursor is by coordinate before the WorksheetChange code executes. (in my code it is variable NowCell) Then I can set the cursor back to the active cell that fired the code and then move the focus one column to the right. In essence, making easier for the person entering data to do it by row. I can't get the syntax of the final statement right and I'm wondering if it has to do with the variable type I'm using for NowCell? I'm also betting that I can't treat a variable like an Excel element, as I have done below. Thoughts? Opinions? Anything is appreciated.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim NowCell As Variant
NowCell = ActiveCell.Address(ReferenceStyle:=xlR1C1)
ActiveSheet.Unprotect Password:="password"
Range("A1:J10").Select
Selection.Locked = False
If ActiveSheet.Range("I4") <> "" Then
ActiveSheet.Range("I4").Locked = True
End If
If ActiveSheet.Range("B4") <> "" Then
ActiveSheet.Range("B4").Locked = True
End If
If ActiveSheet.Range("I6") <> "" Then
ActiveSheet.Range("I6").Locked = True
End If
ActiveSheet.Protect Password:="password"
NowCell.Offset(0, 1).SetFocus
End Sub
Thanks!