[VBA] Working with - sign as a string

danny2001k

New Member
Joined
May 13, 2011
Messages
4
My problem is this:

I have a macro that gets the info from a access db.

I have to check some strings if they have the - sign in them.

Code:
If InStr(string, "-") > 0 Then

My problem that office has some auto formating for the minus sign sometimes, it makes it longer and my code doesn't find that longer sign.
minus.JPG



I tried copying the both minus signes in the vba code but the paste is the same minus: the little one.
 

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
The 'em dash' is ASCII 150 as opposed to the 'en dash' which is ASCII 45.

Try:-
Code:
If InStr(string, chr(45)) > 0 or InStr(string, chr(150)) > 0 Then

Or even:-
Code:
If InStr(string, chr(45)) + InStr(string, chr(150)) > 0 Then

What are you going to do with the little blighters once you've spotted them? Strip them out? Replace them with something else?
 
Last edited:
Upvote 0
Ty, it worked perfect.

Wanted to keep only what is after them.

Final code:

Code:
If InStr(string, Chr(45)) > 0 Or InStr(string, Chr(150)) > 0 Then

If InStr(string, Chr(45)) > 0 Then
minus = InStr(string, Chr(45))
End If

If InStr(string, Chr(150)) > 0 Then
minus = InStr(string, Chr(150))
End If

string = Trim(Right(string, Len(string) - minus))
End If
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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