Find and Replace for ASCII Characters

RachCamp7

New Member
Joined
Aug 26, 2015
Messages
1
I am very new to VBA, but I am learning so please bear with me. I'm creating a "validation/reformatting" tool for a team at work. I am stuck. :(

I want to create a code for finding a specific list of ASCII characters in cells and replacing them. For Example: If "Ä" appears in a cell, I want it to be replaced with "A". I don't want it to remove anything else in that cell, just that one character. I've created a "table" tab that has a list of the specific ASCII codes and the replacement character.

Please help!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi and welcome to the MrtExcel Message Board.

The macro recorder would have helped with this. If you switched it on then went into theHome-->Editing-->Find & Select--> Replace ... menu then it would have recorded some Replace commands for you.

Then I like to make sure that they are going to work on the right worksheet and not just any one that happens to be active but this depends on how you need it to work. So I might add to the recording as follows:
Code:
Sub MakeChanges()
    With ThisWorkbook.Worksheets("Sheet1")
        .Cells.Replace What:="a", Replacement:="b", LookAt:=xlPart, SearchOrder _
            :=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
        .Cells.Replace What:="5", Replacement:="6", LookAt:=xlPart, SearchOrder _
            :=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
        .Cells.Replace What:="z", Replacement:="A1", LookAt:=xlPart, SearchOrder _
            :=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
         .Cells.Replace What:="Z", Replacement:="S2", LookAt:=xlPart, SearchOrder _
            :=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
    End With
End Sub
That changes "a" into "b", "5" into "6", "z" into "A1" and "Z" into "S2". Just substitute the changes you need and add commands as necessary.
 
Upvote 0

Forum statistics

Threads
1,216,499
Messages
6,131,010
Members
449,613
Latest member
MedDash99

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