Split function compare options

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,691
Office Version
  1. 365
Platform
  1. Windows
I'm a bit puzzled by a couple of the Compare options for the Split function.

According to this link:

https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/split-function

The Compare option has these values:

[TABLE="class: grid, width: 700"]
<tbody>[TR]
[TD="align: center"]Value
[/TD]
[TD="align: center"]Variable
[/TD]
[TD="align: center"]Description[/TD]
[/TR]
[TR]
[TD="align: center"]-1[/TD]
[TD]vbUseCompareOption[/TD]
[TD]Performs a comparison using the setting of the Option Compare statement.[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD]vbBinaryCompare[/TD]
[TD]Performs a binary comparison. Case sensitive? Default?[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]vbTextCompare[/TD]
[TD]Performs a textual comparison. Case insensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]vbDatabaseCompare[/TD]
[TD]Microsoft Access only. Performs a comparison based on information in your database.[/TD]
[/TR]
</tbody>[/TABLE]

I tested these Compare settings using this expression:
Code:
A=Split("3.5ft","FT",,see table)

I got these results:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]Compare Setting[/TD]
[TD="align: center"]UBound[/TD]
[TD="align: center"]A(0)[/TD]
[TD="align: center"]A(1)[/TD]
[TD]Comments[/TD]
[/TR]
[TR]
[TD="align: center"]omitted[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]|3.5ft|[/TD]
[TD="align: center"][/TD]
[TD]Case sensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]-1[/TD]
[TD="align: center"]--[/TD]
[TD="align: center"]--[/TD]
[TD="align: center"][/TD]
[TD]Invalid call[/TD]
[/TR]
[TR]
[TD="align: center"]vbUseCompareOption[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]|3.5ft|[/TD]
[TD="align: center"][/TD]
[TD]Case sensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]|3.5ft|[/TD]
[TD="align: center"][/TD]
[TD]Case sensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]vbBinaryCompare[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]|3.5ft|[/TD]
[TD="align: center"][/TD]
[TD]Case sensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]|3.5|[/TD]
[TD="align: center"]||[/TD]
[TD]Case insensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]vbTextCompare[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]|3.5|[/TD]
[TD="align: center"]||[/TD]
[TD]Case insensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]|3.5|[/TD]
[TD="align: center"]||[/TD]
[TD]Case insensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]vbDatabaseCompare[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]|3.5|[/TD]
[TD="align: center"]||[/TD]
[TD]Case insensitive?[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]|3.5|[/TD]
[TD="align: center"]||[/TD]
[TD]Case insensitive?[/TD]
[/TR]
</tbody>[/TABLE]

Questions:


  1. Which one is the default? It appears to be the binary compare (1).
  2. Why do I get an error when I explicitly code "-1", but not when I code vbUseCompareOption, which = -1?
  3. Is the binary compare case sensitive and the text compare case insensitive?
  4. It appears that any value > 1 works the same as 1.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I found the answer to #2 . The website is wrong. the value of vbUseCompareOption is null, not -1.
 
Upvote 0
The default is vbBinaryCompare. This is shown in the function arguments when you type "Split(".

vbBinaryCompare is case sensitive and vbTextCompare is case insensitive.

The same rules apply to other string functions such as Instr and Replace.
 
Upvote 0
The default is vbBinaryCompare. This is shown in the function arguments when you type "Split(".
Ah, good point.

vbBinaryCompare is case sensitive and vbTextCompare is case insensitive.

The same rules apply to other string functions such as Instr and Replace.

Thanks
 
Upvote 0
The default is vbBinaryCompare. This is shown in the function arguments when you type "Split(".
It appears that this method, like the help files, is not perfect. At least on my VB6 system, the argument prompt does not show any default value for the second argument (the delimiter). The default is the space character.

I would think that as long as M$FT has been in business and as much money they have made off of everyone, they could at least fix some of the most obvious and simplest bugs.
 
Upvote 0
At least on my VB6 system, the argument prompt does not show any default value for the second argument (the delimiter). The default is the space character.

I would think that as long as M$FT has been in business and as much money they have made off of everyone, they could at least fix some of the most obvious and simplest bugs.
It is covered in the Help file for the Split function.
 
Upvote 0
It is covered in the Help file for the Split function.

Yes. My point was that some of the defaults are covered in the help file and some in the argument prompt but neither source covers them all. Pretty typical for M$FT.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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