Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

Excel VBA: Replacing text in a specific column with code

$
0
0

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).

[code language="vb"]
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
[/code]

Enjoy!


Viewing all articles
Browse latest Browse all 36188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>