View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default Select Case Syntax

Thanks. I plugged this interpretation of your solution into my code
and it errored out. Here's the code :


Hi. Your original code was not returning a value...
It was just running the macro...

Case 42, 49, 56, 63, 70, 77, 84, 91
InvCol_1 vName, vNum


Note the differences here...

Sub Demo()
Dim Ans

'Return a value
Ans = Run("M", 2, 3)

'Or just run macro
Run "M", 2, 3
End Sub

Function M(x, y)
M = x * y
End Function

= = = = = = =
HTH
Dana DeLouis



On 1/17/2010 6:59 PM, Minitman wrote:
Hey Rick,

Thanks. I plugged this interpretation of your solution into my code
and it errored out. Here's the code :

Dim iCol As Integer

Case "I_"
Select Case vNum
Case 42 to 97
iCol = (1+(vNum-42)Mod 7)
If Not iCol = 3 then _
Application.Run "InvCol_"& iCol(vName, vNum)

This look like it should work but doesn't. Since there is no code for
column 3, it is considered an illegal condition. Hence, the if
statement to exclude it.

When I try to run this code I get an "expected array" error.

And what do I have to do to get "Application.Run" to work?

Any idea's?

-Minitman



On Sun, 17 Jan 2010 11:12:16 -0500, "Rick Rothstein"
wrote:

Of course, if you use Application.Run to run your "InvCol_x" subroutines, you can eliminate the Select Case block entirely...

Case "I_"
Application.Run "InvCol_"& (1 + (vNum - 42) Mod 7)

Again, the above covers the case where your vNum values could be 44, 51, 58, 65, 72, 79, 86, 93 which you omitted from your original Select Case block.

--
Rick (MVP - Excel)


"Rick wrote in message ...
Assuming you accidentally left out the case covering the vNum values of 44, 51, 58, 65, 72, 79, 86, 93; then here is the simplified Case "I_" you asked about...

Case "I_"
Select Case (vNum - 42) Mod 7
Case 0
InvCol_1 vName, vNum
Case 1
InvCol_2 vName, vNum
Case 2
InvCol_4 vName, vNum
Case 3
InvCol_4 vName, vNum
Case 4
InvCol_5 vName, vNum
Case 5
InvCol_6 vName, vNum
Case 6
InvCol_7 vName, vNum
End Select




--
= = = = = = =
HTH :)
Dana DeLouis