How to use True or Null as a Case in Select Case Statement?

prabha_friend

Board Regular
Joined
Jun 28, 2011
Messages
95
How to shorten this statement:

If sheet.Previous.Range(SingleArea.Address).HasFormula = True Or IsNull(sheet.Previous.Range(SingleArea.Address).HasFormula) Then

Select Case
Case True or Null
Statement
End Select
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
First, the HasFormula property will never be Null.
It's an absolute boolean, it's either True or False.

So you can just do this

Code:
If sheet.Previous.Range(SingleArea.Address).HasFormula = True Then
    'Do this if it Has a formula
Else
    'Do That if it does not have a formula
End If
 
Upvote 0
I stand corrected.
It seemed obvious to me that it was only a true or false statement.
That's only true if the range tested is a single cell...Which your original post led me to believe..
Apparently It's Null if the range is a multicell range, and some cells have formulas and some don't.

Anyway..

I don't think you can use the Null result in Select Case, because it's Null, has no value at all..
But you could test for False, Do Nothing, then use the ELSE part of the select case for your action if Null or True.

Code:
Select Case Sheet.Previous.Range(SingleArea.Address).HasFormula
    Case False
        'do Nothing
    Case Else
        'Statement
        MsgBox "It's True or Null"
End Select
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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