StevensNet.com

...Because someone's gotta tell the story...

Blogs

To return to the main Blog List, click Full Blog Listing.

Tags

Excel
Technical

Excel VBA: Replacing text in a specific column with code

Friday, December 22, 2017 in Technical Articles (Views: 571)
Another really quick code snippet to replace text in a specific column through code.

Usage is simple: ReplaceTextInColumn "A", "Hello", "Aloha"
Where "A" is the column to replace text in.
Hello is the text to find, and Aloha is the text to replace Hello with (thinking warm this winter).

You can extend this to add more flexibility to the sub arguments (adding case matching, etc).

Sub ReplaceTextInColumn(strColumn, strSource, strDest As String)

Columns("" + strColumn + "").Replace What:="" + strSource + "", _
Replacement:="" + strDest + "", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False

End Sub


Enjoy!

 

Related Blogs You May Be Interested In:


To leave a comment, please log in and/or register.