LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Is If-Then Else limited to seven Elseif's??

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLOOKUP is very limited Bobby Excel Worksheet Functions 7 October 18th 05 08:20 PM
Date limited Michael Excel Programming 2 July 10th 05 08:16 PM
Limited logins Bruise Excel Worksheet Functions 0 May 24th 05 12:51 AM
Limited Sumif Maarten Excel Discussion (Misc queries) 2 May 3rd 05 01:11 PM
Dir() limited to 48 files? Claude Excel Programming 2 October 30th 03 10:20 AM


All times are GMT +1. The time now is 06:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"