ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   I Know I'm Missing Something...but what? (https://www.excelbanter.com/excel-programming/332946-i-know-im-missing-something-but-what.html)

GreenMonster[_2_]

I Know I'm Missing Something...but what?
 
I have the following lines of code running as a Private Function within my macro:

Private Function DetermineColumn(cell As Range) As Long
Dim sAttachmentType As String
Dim sAttachmentColor As String
Dim sAttachmentSize As String
sAttachmentType = LCase(cell(1, 11).Value)
sAttachmentColor = LCase(cell(1, 12).Value)
sAttachmentSize = Trim(cell(1, 13).Text)
DetermineColumn = 0

If sAttachmentType = "steel angle" Then
Select Case sAttachmentColor
Case "white"
If sAttachmentSize = "15/16" Then
DetermineColumn = 5
ElseIf sAttachmentSize = "9/16" Then
DetermineColumn = 7
Else
DetermineColumn = 0
End If

Case "bronze"
DetermineColumn = 9
Case "wood"
DetermineColumn = 11
Case "black"
DetermineColumn = 13
Case "paint"
DetermineColumn = 15
End Select

ElseIf sAttachmentType = "steel tape" Then
Select Case sAttachmentColor
Case "white"
DetermineColumn = 17
Case "paint"
DetermineColumn = 19
End Select
End If

End Function

I added the following If statement to the code

If sAttachmentType = "steel angle" Then
Select Case sAttachmentColor
Case "white"
If sAttachmentSize = "15/16" Then
DetermineColumn = 5
ElseIf sAttachmentSize = "9/16" Then
DetermineColumn = 7
Else
DetermineColumn = 0
End If

Case "bronze"
DetermineColumn = 9
Case "wood"
DetermineColumn = 11
Case "black"
DetermineColumn = 13
Case "paint"
DetermineColumn = 15
End Select

ElseIf sAttachmentType = "Inside Angle" Then
Select Case sAttachmentColor
Case "White"
DetermineColumn = 17
Case "Paint"
DetermineColumn = 19
End Select


ElseIf sAttachmentType = "steel tape" Then
Select Case sAttachmentColor
Case "white"
DetermineColumn = 21
Case "paint"
DetermineColumn = 23
End Select
End If

End Function

When I run the macro it skips right over the new ElseIf statement and acts as though it isn't there. I recieve no errors and no result data if "Inside Angle" is chosen as my sAttachmentType. If "Steel Angle" or "Steel Tape" is chosen as my sAttachment Type then the result data is calculated correctly.

Any ideas? I'm sure it's something simple but I haven't been able to see it.



Tom Ogilvy

I Know I'm Missing Something...but what?
 
A logical approach would be to do

sAttachmenttype = lcase( something).

if that is the case, then this can never be true

sAttachmentType = "Inside Angle"


you might alter your test to

sAttachmentType = "inside angle"


--
Regards,
Tom Ogilvy


"GreenMonster" wrote in message
...
I have the following lines of code running as a Private Function within my
macro:

Private Function DetermineColumn(cell As Range) As Long
Dim sAttachmentType As String
Dim sAttachmentColor As String
Dim sAttachmentSize As String
sAttachmentType = LCase(cell(1, 11).Value)
sAttachmentColor = LCase(cell(1, 12).Value)
sAttachmentSize = Trim(cell(1, 13).Text)
DetermineColumn = 0

If sAttachmentType = "steel angle" Then
Select Case sAttachmentColor
Case "white"
If sAttachmentSize = "15/16" Then
DetermineColumn = 5
ElseIf sAttachmentSize = "9/16" Then
DetermineColumn = 7
Else
DetermineColumn = 0
End If

Case "bronze"
DetermineColumn = 9
Case "wood"
DetermineColumn = 11
Case "black"
DetermineColumn = 13
Case "paint"
DetermineColumn = 15
End Select

ElseIf sAttachmentType = "steel tape" Then
Select Case sAttachmentColor
Case "white"
DetermineColumn = 17
Case "paint"
DetermineColumn = 19
End Select
End If

End Function

I added the following If statement to the code

If sAttachmentType = "steel angle" Then
Select Case sAttachmentColor
Case "white"
If sAttachmentSize = "15/16" Then
DetermineColumn = 5
ElseIf sAttachmentSize = "9/16" Then
DetermineColumn = 7
Else
DetermineColumn = 0
End If

Case "bronze"
DetermineColumn = 9
Case "wood"
DetermineColumn = 11
Case "black"
DetermineColumn = 13
Case "paint"
DetermineColumn = 15
End Select

ElseIf sAttachmentType = "Inside Angle" Then
Select Case sAttachmentColor
Case "White"
DetermineColumn = 17
Case "Paint"
DetermineColumn = 19
End Select


ElseIf sAttachmentType = "steel tape" Then
Select Case sAttachmentColor
Case "white"
DetermineColumn = 21
Case "paint"
DetermineColumn = 23
End Select
End If

End Function

When I run the macro it skips right over the new ElseIf statement and acts
as though it isn't there. I recieve no errors and no result data if "Inside
Angle" is chosen as my sAttachmentType. If "Steel Angle" or "Steel Tape" is
chosen as my sAttachment Type then the result data is calculated correctly.

Any ideas? I'm sure it's something simple but I haven't been able to see
it.





All times are GMT +1. The time now is 01:20 AM.

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