Replace question

IvenBach

Board Regular
Joined
May 31, 2008
Messages
212
I have a macro that will go through and check for Bad/Unwanted data or characters and replaces them with Good. I have come across an instance with the character ⅜ - CODE says its 63 which is a Question Mark ( ? ). Took me a while to figure it out as when I ran my code and it changed everything to the ( -3/8 ). I have done this with success for ¼, ½, ¾, ©, ®, etc... At a loss and hoping to get some guidance or suggestions on this.

This is how I have my code laid out. Meant to compile all my arrays into 1 looping through instead of copy+pasting.

Code:
array1 = Array("⅜")
array[B]...[/B]

arrayreplace = Array("-3/8", [B]...[/B] )
arrayCOMPILE = Array(array1, array[B]...[/B])

For HOSTARRAY = LBound(arrayCOMPILE) To UBound(arrayCOMPILE)
        For lngDATA = LBound(arrayCOMPILE(HOSTARRAY)) To UBound(arrayCOMPILE(HOSTARRAY))
            strpass = arrayCOMPILE(HOSTARRAY)(lngDATA)
            FindHiLight strpass
            Selection.Replace what:=arrayCOMPILE(HOSTARRAY)(lngDATA), Replacement:=arrayreplace(HOSTARRAY), _
                LookAt:=xlPart, SearchOrder:=xlByRows
        Next
Next
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I'm not sure I understand your question. If you are trying to replace the question mark character, you have to precede it with a Tilde character

~?

The question mark character is used as a wildcard in the Find\Replace function. Preceding it with a tilde designates that you want to replace a literal question mark.
 
Upvote 0
Replace: "⅜" - With: "-3/8"

I used =CODE("⅜") and it came up with 63, whereas 63 is a question mark. When I initially ran the macro (as expected with a question mark - ? - It replaced everything with -3/8. I would like to know how to figure out what code the ⅜ symbol is using and use that within my macro code to properly remove it. It is unicode character 215C and I don't know how to deal with unicode information yet. Anyone able to direct me down the right path?
 
Upvote 0
This would be very simple, if you just looped through the array using Replace on the spreadsheet. It is ChrW(&H215C)

Code:
Sub test()
Dim replacewhat, replacewith, x As Long
replacewhat = Array(ChrW(&H215C))
replacewith = Array("-3/8")
For x = LBound(replacewhat) To UBound(replacewith)
    Range("A:A").Replace replacewhat(x), replacewith(x)
Next x
End Sub
 
Last edited:
Upvote 0
Thank you HOTPEPPER. Works perfectly.

In the sample code that you posted you list it as &H215C. Why, if you don't mind me asking, do you put the &H in front? I tried removing it but came up with Syntax Error or Compile Error. Is there anywhere I can read up on this to learn more?
 
Upvote 0
&H indicates that the number to follow is in hexadecimal.

In decimal it would be ChrW(8540)
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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