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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,215,497
Messages
6,125,157
Members
449,208
Latest member
emmac

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