Solved: Problem with "Instr" when called with an Empty Thread

Mackeral

Board Regular
Joined
Mar 7, 2015
Messages
249
Office Version
  1. 365
Platform
  1. Windows
If you call "Instr" with a null argument as in "Instr("Whatever","")" you always get back a 1.

It should return a 0 indicateing that it didn't match anything.

My solution:
Code:
Function In_Str(Look_In, For_Text)    ' Correcting "Instr" function.
    ' 7/3/18 Created. WML
    
    Prog = "In_Str"
    
    If For_Text = "" Then
        In_Str = 0
    Else
        In_Str = InStr(Look_In, For_Text)
    End If
    
End Function ' In_Str()
 
Hmm. Rattling around in my brain is a dim recollection that I've read that, but I can't duplicate it

? Range("A1:A10").Interior.Color = vbWhite returns True if all cells are white, and False otherwise
? Range("A1:A10").Interior.Color returns vbWhite if all cells are white and 0 otherwise
? Range("A1:A10").Value = 1 returns type mismatch regardless of value

Can you give an example, Rory?

A cell cannot contact the value Null.
 
Last edited:
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I agree it's not something you'll come across often though! :)
 
Upvote 0

Forum statistics

Threads
1,225,757
Messages
6,186,850
Members
453,379
Latest member
gabriellegonzalez

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