Home |
Search |
Today's Posts |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I would eliminate the lines indicated
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim Left_Value as Variant, Right_Value As Variant 'Set Left_Value = Nothing '<= eliminate 'Set Right_Value = Nothing '<= eliminate set should only be used with object and you are not using Left_Value and Right_Value as Objects. -- Regards, Tom Ogilvy "rudawg" wrote in message ... Tom, It seems my last reply got lost. What I can't figure out is why the following code does not work. Can you see anything obvious that would be giving me trouble? I am using windows XP and Excel 2003. The error I get is "Type mismatch (Error 13)" I have re-posted my code for better visibility. I am sure it is not the most efficient or elegant approach but I am very new to VBA. Can you offer any suggestions? Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim Left_Value, Right_Value As Variant Set Left_Value = Nothing Set Right_Value = Nothing If Target.Column = 13 Then '<----M Left_Value = ActiveCell.Offset([-1], [-1]).Text Right_Value = ActiveCell.Offset([+1], [-1]).Text [b2] = Left_Value [af2] = Right_Value ' ElseIf Target.Column = 14 Then '<----N Left_Value = ActiveCell.Offset([-2], [-1]).Text Right_Value = ActiveCell.Offset([+2], [-1]).Text [b2] = Left_Value [af2] = Right_Value ' ElseIf Target.Column = 15 Then '<----O Left_Value = ActiveCell.Offset([-4], [-1]).Text Right_Value = ActiveCell.Offset([+4], [-1]).Text [b2] = Left_Value [af2] = Right_Value ' ElseIf Target.Column = 16 Then '<----P Left_Value = ActiveCell.Offset([-8], [-1]).Text Right_Value = ActiveCell.Offset([+8], [-1]).Text [b2] = Left_Value [af2] = Right_Value ' ElseIf Target.Column = 18 Then '<----R Left_Value = ActiveCell.Offset([-7], [-2]).Text Right_Value = ActiveCell.Offset([+25], [-2]).Text [b2] = Left_Value [af2] = Right_Value ' ElseIf Target.Column = 20 Then '<----T Left_Value = ActiveCell.Offset([-25], [2]).Text Right_Value = ActiveCell.Offset([+7], [2]).Text [b2] = Left_Value [af2] = Right_Value ' ElseIf Target.Column = 22 Then '<----V Left_Value = ActiveCell.Offset([-8], [2]).Text Right_Value = ActiveCell.Offset([+8], [2]).Text [b2] = Left_Value [af2] = Right_Value ElseIf Target.Column = 24 Then '<----X Left_Value = ActiveCell.Offset([-4], [1]).Text Right_Value = ActiveCell.Offset([+4], [1]).Text [b2] = Left_Value [af2] = Right_Value ' ElseIf Target.Column = 25 Then '<----Y Left_Value = ActiveCell.Offset([-2], [1]).Text Right_Value = ActiveCell.Offset([2], [1]).Text [b2] = Left_Value [af2] = Right_Value ElseIf Target.Column = 26 Then '<----Z Left_Value = ActiveCell.Offset([-1], [1]).Text Right_Value = ActiveCell.Offset([1], [1]).Text [b2] = Left_Value [af2] = Right_Value End If End Sub Thanks, "Tom Ogilvy" wrote: No - as an example Sub ABCD() v = Int(Rnd() * 12 + 1) If v = 1 Then MsgBox 1 ElseIf v = 2 Then MsgBox 2 ElseIf v = 3 Then MsgBox 3 ElseIf v = 4 Then MsgBox 4 ElseIf v = 5 Then MsgBox 5 ElseIf v = 6 Then MsgBox 6 ElseIf v = 7 Then MsgBox 7 ElseIf v = 8 Then MsgBox 8 ElseIf v = 9 Then MsgBox 9 ElseIf v = 10 Then MsgBox 10 Else MsgBox "10" End If End Sub works fine. -- Regards, Tom Ogilvy "rudawg" wrote: I seem to be running into the same limit as I would with a function of nested ifs. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VLOOKUP is very limited | Excel Worksheet Functions | |||
Date limited | Excel Programming | |||
Limited logins | Excel Worksheet Functions | |||
Limited Sumif | Excel Discussion (Misc queries) | |||
Dir() limited to 48 files? | Excel Programming |