VBA If statement not resolving correctly

gers1978

Board Regular
Joined
Sep 9, 2014
Messages
74
I have a function where a string and a string-based array are passed in.

Using the VBE Watch function I can see the string passed in is:

Code:
TD1a/b/ PMO & CT

The array contains:

Code:
TD1a/b/ PMO & CT
TD1a/b/ PMO & CT
""

The line:

Code:
If staffName = whichArray(intCount) Then

is resolving to False, in other words it's skipping to the Else part, even when intCount = 0 or 1.

However if I run it when the string and array contain "TD1" it works fine.

Seems like either the /, space or & are causing issues?

Also posted here: http://www.ozgrid.com/forum/showthread.php?t=200657&p=774921#post774921
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
My first guess is that there's a space, or non-displayable character in one of your strings. Stop your macro at that comparison line, and check the length of each string. If they're not the same, then they won't match. If they are the same, then you may need to use Mid and check the strings byte by byte. Once you see what's happening, you can use some of the other string processing functions to massage your data so that you can compare them.
 
Upvote 0
My first guess is that there's a space, or non-displayable character in one of your strings. Stop your macro at that comparison line, and check the length of each string. If they're not the same, then they won't match. If they are the same, then you may need to use Mid and check the strings byte by byte. Once you see what's happening, you can use some of the other string processing functions to massage your data so that you can compare them.

You're right, I used the Immediate Window to check the length of the string vs length of array element and it was 16 vs 15, one had a space at the end!
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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