ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with Case Please (https://www.excelbanter.com/excel-programming/387449-help-case-please.html)

St@cy

Help with Case Please
 
Why am I getting an answer of 1 everytime? The function seems to be skipping
the Case programming. What do I need to do to fix this?

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case Level = "L"
ColNum = 2
Case Level = "E"
ColNum = 10
Case Level = "M"
ColNum = 18
Case Level = "D"
ColNum = 26
Case Level = "A"
ColNum = 34
End Select
Select Case Form
Case Form = 7
ColNum = ColNum + 0
Case Form = 8
ColNum = ColNum + 2
Case Form = 9
ColNum = ColNum + 4
Case Form = 10
ColNum = ColNum + 6
End Select
TabeGECol = ColNum
End Function

Dave Peterson

Help with Case Please
 
Maybe you're not passing a nice Level value to the function?????

Or maybe you're passing a lower case letter????

Select Case ucase(Level)

St@cy wrote:

Why am I getting an answer of 1 everytime? The function seems to be skipping
the Case programming. What do I need to do to fix this?

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case Level = "L"
ColNum = 2
Case Level = "E"
ColNum = 10
Case Level = "M"
ColNum = 18
Case Level = "D"
ColNum = 26
Case Level = "A"
ColNum = 34
End Select
Select Case Form
Case Form = 7
ColNum = ColNum + 0
Case Form = 8
ColNum = ColNum + 2
Case Form = 9
ColNum = ColNum + 4
Case Form = 10
ColNum = ColNum + 6
End Select
TabeGECol = ColNum
End Function


--

Dave Peterson

RB Smissaert

Help with Case Please
 
Try this:

Function TabeGECol(Level As String, Form As Integer) As Integer

Dim ColNum As Integer

ColNum = 1

Select Case Level
Case "L"
ColNum = 2
Case "E"
ColNum = 10
Case "M"
ColNum = 18
Case "D"
ColNum = 26
Case "A"
ColNum = 34
End Select

Select Case Form
Case 7
ColNum = ColNum + 0
Case 8
ColNum = ColNum + 2
Case 9
ColNum = ColNum + 4
Case 10
ColNum = ColNum + 6
End Select

TabeGECol = ColNum

End Function


RBS


"St@cy" wrote in message
...
Why am I getting an answer of 1 everytime? The function seems to be
skipping
the Case programming. What do I need to do to fix this?

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case Level = "L"
ColNum = 2
Case Level = "E"
ColNum = 10
Case Level = "M"
ColNum = 18
Case Level = "D"
ColNum = 26
Case Level = "A"
ColNum = 34
End Select
Select Case Form
Case Form = 7
ColNum = ColNum + 0
Case Form = 8
ColNum = ColNum + 2
Case Form = 9
ColNum = ColNum + 4
Case Form = 10
ColNum = ColNum + 6
End Select
TabeGECol = ColNum
End Function



Gary''s Student

Help with Case Please
 
Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case "L"
ColNum = 2
Case "E"
ColNum = 10
Case "M"
ColNum = 18
Case "D"
ColNum = 26
Case "A"
ColNum = 34
End Select
Select Case Form
Case 7
ColNum = ColNum + 0
Case 8
ColNum = ColNum + 2
Case 9
ColNum = ColNum + 4
Case 10
ColNum = ColNum + 6
End Select

TabeGECol = ColNum
End Function

--
Gary''s Student - gsnu200715

David McRitchie

Help with Case Please
 
In general macro comparisons are case sensitive,
and worksheet formulas are case in-sensitive. See
http://www.mvps.org/dmcritchie/excel...tm#sensitivity

Select Case UCase(Level)
---
HTH,
David McRitchie, Microsoft MVP - Excel
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"St@cy" wrote in message ...
Why am I getting an answer of 1 everytime? The function seems to be skipping
the Case programming. What do I need to do to fix this?

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case Level = "L"
ColNum = 2
Case Level = "E"
ColNum = 10
Case Level = "M"
ColNum = 18
Case Level = "D"
ColNum = 26
Case Level = "A"
ColNum = 34
End Select
Select Case Form
Case Form = 7
ColNum = ColNum + 0
Case Form = 8
ColNum = ColNum + 2
Case Form = 9
ColNum = ColNum + 4
Case Form = 10
ColNum = ColNum + 6
End Select
TabeGECol = ColNum
End Function




Art

Help with Case Please
 
It probably has to do with the parameters you're passing in. Try this. Put
a Case Else statement as the last Case in each of your selects (a good
practice anyway).
You might try to put a Stop as the statement in the case else. Your code
will probably stop there. You can then use the immediate window to find out
what the value of Level is.

"St@cy" wrote:

Why am I getting an answer of 1 everytime? The function seems to be skipping
the Case programming. What do I need to do to fix this?

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case Level = "L"
ColNum = 2
Case Level = "E"
ColNum = 10
Case Level = "M"
ColNum = 18
Case Level = "D"
ColNum = 26
Case Level = "A"
ColNum = 34
End Select
Select Case Form
Case Form = 7
ColNum = ColNum + 0
Case Form = 8
ColNum = ColNum + 2
Case Form = 9
ColNum = ColNum + 4
Case Form = 10
ColNum = ColNum + 6
End Select
TabeGECol = ColNum
End Function


St@cy

Help with Case Please
 
Thanks! That did it. ...so simiple

"Gary''s Student" wrote:

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case "L"
ColNum = 2
Case "E"
ColNum = 10
Case "M"
ColNum = 18
Case "D"
ColNum = 26
Case "A"
ColNum = 34
End Select
Select Case Form
Case 7
ColNum = ColNum + 0
Case 8
ColNum = ColNum + 2
Case 9
ColNum = ColNum + 4
Case 10
ColNum = ColNum + 6
End Select

TabeGECol = ColNum
End Function

--
Gary''s Student - gsnu200715


Dana DeLouis

Help with Case Please
 
Just something different...

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Long

ColNum = 1 'Default

Select Case UCase(Level)
Case "L", "E", "M", "D", "A"
' { 2, 10, 18, 26, 34}
ColNum = 429295654 Mod Asc(UCase(Level))
End Select

Select Case Form
Case 7, 8, 9, 10
ColNum = ColNum + 2 * Form - 14
End Select
TabeGECol = ColNum
End Function

--
HTH :)
Dana DeLouis
Windows XP & Office 2007


"St@cy" wrote in message
...
Why am I getting an answer of 1 everytime? The function seems to be
skipping
the Case programming. What do I need to do to fix this?

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case Level = "L"
ColNum = 2
Case Level = "E"
ColNum = 10
Case Level = "M"
ColNum = 18
Case Level = "D"
ColNum = 26
Case Level = "A"
ColNum = 34
End Select
Select Case Form
Case Form = 7
ColNum = ColNum + 0
Case Form = 8
ColNum = ColNum + 2
Case Form = 9
ColNum = ColNum + 4
Case Form = 10
ColNum = ColNum + 6
End Select
TabeGECol = ColNum
End Function




Gary''s Student

Help with Case Please
 
You are very welcome
--
Gary''s Student - gsnu200715


"St@cy" wrote:

Thanks! That did it. ...so simiple

"Gary''s Student" wrote:

Function TabeGECol(Level, Form) As Integer
Dim ColNum As Integer
ColNum = 1
Select Case Level
Case "L"
ColNum = 2
Case "E"
ColNum = 10
Case "M"
ColNum = 18
Case "D"
ColNum = 26
Case "A"
ColNum = 34
End Select
Select Case Form
Case 7
ColNum = ColNum + 0
Case 8
ColNum = ColNum + 2
Case 9
ColNum = ColNum + 4
Case 10
ColNum = ColNum + 6
End Select

TabeGECol = ColNum
End Function

--
Gary''s Student - gsnu200715



All times are GMT +1. The time now is 05:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com