Find replace macro signle byte with double byte

bizpioneer

New Member
Joined
Apr 28, 2014
Messages
31
So I am trying find replace macro to replace any % "single byte" to % double byte but looks like macro doesnt recogize double bytes

So here is my macro

Range("A1").Select
columns("K:N").Select
Selection.Replace What:="%", Replacement:="%", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("H1").Select
Range("A1").Select

When I run it just replace the single byte sign with a single byte sign, anyway I can fix that so it replaces it with the double byte?

Thanks,
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi

First of all: all characters in excel vba are, by default, double byte characters.

I think what you want is to replace the character with code H0025 (the default Percent "%" sign, from the ascii table) by the character HFF05 (Unicode Fullwidth Percent Sign).

In vba you can specify a character given its code with ChrW()

I don't understand what the Select's are doing in your code. Using Select in vba is bad practice, it makes the code less efficient and more difficult to read.

If I understand correctly you want:


Code:
Columns("K:N").Replace What:="%", Replacement:=ChrW(&HFF05), LookAt:=xlPart, _
    SearchOrder:=xlByRows, SearchFormat:=False, ReplaceFormat:=False

Please try
 
Upvote 0
It worked! thanks a million. To answer your question the selects are there because I simply suck :D I will take them out in the future! Thanks again :)
 
Upvote 0
Hey, it's me again. I would like to do the same thing, this time replacing the following signs " & ® with the double byte alternatives, any idea how to get the code for these? is there some kind of library that has all the codes for the double byte characters?
 
Upvote 0
To get the ascii code for a specific character, you can just type that character in a cell (say A1)
Then this formula in another cell will tell you it's code

=CODE(A1)
 
Upvote 0
Oh, differnet standard....

It's still valid, but in vba use
Replacement:=Chr(63)
instead of
Replacement:=ChrW(&HFF05)
 
Upvote 0
didn't work when I used =Chr(63) it replaced the sign with a question mark, while ChrW(&HFF05) worked perfectly :confused: here is the formula that I used

Range("A1").Select
Cells.Replace What:="%", Replacement:=Chr(63), LookAt:=xlPart, SearchOrder _
:=xlByRows, SearchFormat:=False, ReplaceFormat:=False
 
Upvote 0

Forum statistics

Threads
1,214,411
Messages
6,119,356
Members
448,888
Latest member
Arle8907

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