Using Case statement with True and False keywords

ashgaroth

New Member
Joined
Mar 10, 2010
Messages
18
I have an Excel 'database' that I need to update some records on but ubfortunately the Select Case statement is not working as I expected it to.

This the code that I have:

Select Case cbVI2
Case = True And cbHI2 = True
Range("U" & Count).Value = "DUAL"
Case = True And cbHI2 = False
Range("U" & Count).Value = "VI"
Case False And cbHI2 = True
Range("U" & Count).Value = "HI"
Case False And cbHI2 = False
Range("U" & Count).Value = " "
End Select

cbVI2 is a checkbox and at this point it's value is FALSE, cbHI2 is also a checkbox but it's value at this point is TRUE.

What I am expecting as it runs through the Select Case routine is that the first 2 statements are ignored and the third statement is the working statement. However, when I hover the mouse over the expressions I see the following:

True = True
cbHI2 = True

The first statement is ignored but the second works leading to my cell having 'VI' put into it instead of 'HI' :confused:

I have 'debugged' this over and over and cannot see why this happening.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You can't do it like that if you want a compound expression on each line. Perhaps like this though:

Code:
Select Case True
  Case (cbv12.Value And cbH12.Value)
    'what you want when both True
  Case (cbV12.Value And Not cbH12.Value)
    'cbV12 True, cbH12 False
  Case (cbH12.Value And Not cbV12.Value)
    '...
  '....
 End Select
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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