Having problems getting a "Select Case" function to work properly

jameslytle

New Member
Joined
Jul 30, 2018
Messages
21
I am having a problem getting the "Select Case" part of my VBA to work. The Case "ERAText.Value" is provided from another UserForm and is a value of 1, 2 or 3. In the case of 1 and 2 I want it to run the section listed under it which is to show a text box and list the value of "Human" in it. This seems to work just fine.

However, If I wanted to the case 3 to work where it would show a Combo Box showing a list to select from with the default value of "Human" showing up first. When "3" is selected it acts as if the first Case Option "< 3" was selected and only shows the text box with "Human" in it.

What am I doing wrong?

Thanks in advance for any assistance.

**************************************
Select Case ERAText.Value
Case Is < "3"
Me.PhenoText.Visible = True
Me.PhenoCombo.Visible = False
With PhenoText
.Value = "Human"
End With
Case Is = "3"
Me.PhenoCombo.Visible = True
Me.PhenoText.Visible = False
With PhenoCombo
.List = Range("PhenoType").Value
.Value = "Human"
End With
End Select
*******************************


Jim
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try removing the double-quotes from around the 3 in both Case clauses.
Putting double-quotes around them indicates that they are text and not numeric.
 
Upvote 0
Alternatively if the values are text try
Code:
Select Case ERAText.Value
   Case "1", "2"
      Me.PhenoText.Visible = True
      Me.PhenoCombo.Visible = False
      With PhenoText
         .Value = "Human"
      End With
   Case "3"
      Me.PhenoCombo.Visible = True
      Me.PhenoText.Visible = False
      With PhenoCombo
         .List = Range("PhenoType").Value
         .Value = "Human"
      End With
End Select
 
Upvote 0
When I remove the quotes it does not seem to recognize anything so it shows both the text box overlapping the Combobox (since they both are to show up in the same location) but it does not tie the list (in the case of choosing selection 3) or the text "Human" (in the case of choosing section 1 or 2).

I have also changed the programming so that it looks at the "Text" of ERAText instead of "Value" but I get similar results.
 
Last edited:
Upvote 0
Confirm that the value is what you think it, and check to see if it is seen to be numeric or not.
You can do that with a MsgBox like this:
Code:
[COLOR=#ff0000]Dim ERA
ERA = ERAText.Value

MsgBox "Value is: " & ERA & vbCrLf & "Is it numeric? " & IsNumeric(ERA)[/COLOR]

Select Case ERA
   Case "1", "2"
      Me.PhenoText.Visible = True
      Me.PhenoCombo.Visible = False
      With PhenoText
         .Value = "Human"
      End With
   Case "3"
      Me.PhenoCombo.Visible = True
      Me.PhenoText.Visible = False
      With PhenoCombo
         .List = Range("PhenoType").Value
         .Value = "Human"
      End With
      
End Select
 
Upvote 0
The only thing I can get to work is what i originally posted. What I did find out is that whatever I have listed under the Case with the "<" function works but the Case with the "=" will not be seen at all.

Any suggestions?
 
Upvote 0
Any suggestions?
Yes. Please try what I suggested in my last post and tell us what the message box returns.
That will let us know what we are working with.
 
Upvote 0
How about
Code:
Select Case Val(ERAText.Value)
Case Is < 3
Me.PhenoText.Visible = True
Me.PhenoCombo.Visible = False
With PhenoText
.Value = "Human"
End With
Case Is = 3
Me.PhenoCombo.Visible = True
Me.PhenoText.Visible = False
With PhenoCombo
.List = Range("PhenoType").Value
.Value = "Human"
End With
End Select
 
Upvote 0
Joe4.

It returned a false which I am assuming means it is text. Hence the fact that it will work when I put the quotes on and not without them. It still does not explain why it does not seem to recognize the Case = and only recognize the case <.
 
Upvote 0
Fluff,

When I added the bit you show I still get the same result where it will work with anything listed under the case with the "<" but not with the "="
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top