Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My Worksheet_SelectionChange code includes:
.... If (Target.Column = 9 And Target.Offset(0, -4) < "PR") Then [line2] Target.Offset(0, -1) = StrConv(ActiveCell.Offset(0, -1), vbProperCase) ElseIf Target.Column = 9 And Target.Offset(0, -4) = "PR" Then Target.Offset(0, -1) = StrConv(ActiveCell.Offset(0, -1), vbUpperCase) End If .... Usually works okay, but sometimes (i.e., when Target.column=3), the code goes to line2 (as if the target.column was 9), and runs line2. What do you think is up? TIA |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi zSplash,
Do you have an On Error Resume Next before your code in hopes of catching the case where you're in columns A:D? The Offset method will raise an error when you try to go 4 cells to the left if that will take you to the "left" of column A. If you did use On Error Resume Next, then that would explain the behavior - the If statement causes an error, so execution continues inside the If block. Try an On Error Goto; better yet, check the value of Cells(Target.Row, 5) instead of using Offset, as you're only checking the value if the selection is in Column 9 anyway. -- Regards, Jake Marx www.longhead.com [please keep replies in the newsgroup - email address unmonitored] zSplash wrote: My Worksheet_SelectionChange code includes: ... If (Target.Column = 9 And Target.Offset(0, -4) < "PR") Then [line2] Target.Offset(0, -1) = StrConv(ActiveCell.Offset(0, -1), vbProperCase) ElseIf Target.Column = 9 And Target.Offset(0, -4) = "PR" Then Target.Offset(0, -1) = StrConv(ActiveCell.Offset(0, -1), vbUpperCase) End If ... Usually works okay, but sometimes (i.e., when Target.column=3), the code goes to line2 (as if the target.column was 9), and runs line2. What do you think is up? TIA |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Precisely right, Jake. Thanks so much.
st. "Jake Marx" wrote in message ... Hi zSplash, Do you have an On Error Resume Next before your code in hopes of catching the case where you're in columns A:D? The Offset method will raise an error when you try to go 4 cells to the left if that will take you to the "left" of column A. If you did use On Error Resume Next, then that would explain the behavior - the If statement causes an error, so execution continues inside the If block. Try an On Error Goto; better yet, check the value of Cells(Target.Row, 5) instead of using Offset, as you're only checking the value if the selection is in Column 9 anyway. -- Regards, Jake Marx www.longhead.com [please keep replies in the newsgroup - email address unmonitored] zSplash wrote: My Worksheet_SelectionChange code includes: ... If (Target.Column = 9 And Target.Offset(0, -4) < "PR") Then [line2] Target.Offset(0, -1) = StrConv(ActiveCell.Offset(0, -1), vbProperCase) ElseIf Target.Column = 9 And Target.Offset(0, -4) = "PR" Then Target.Offset(0, -1) = StrConv(ActiveCell.Offset(0, -1), vbUpperCase) End If ... Usually works okay, but sometimes (i.e., when Target.column=3), the code goes to line2 (as if the target.column was 9), and runs line2. What do you think is up? TIA |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Unexplainable XIRR #NUM! Error | Excel Worksheet Functions | |||
Target cell reference moves when target is cut and pasted | Excel Discussion (Misc queries) | |||
Unexplainable Formulas | Excel Discussion (Misc queries) | |||
Unexplainable results from my vlookup | Excel Worksheet Functions | |||
Unexplainable Duplicate Entries | Excel Discussion (Misc queries) |