Flex Texmex
Flex Texmex

Reputation: 1084

How can I use excel Replace <*> in excel vba like in excel? (regular expressions)

If you want to delete html tags in excel one way is to use the replace function. I search for "<*>" and replace it by "". So I just delete every html tag. Excel VBA also has a replace function but it is far more stupid. If I write:

temp2 = Replace(temp2, "<*>", "")

It doesn't interpret "< * >" as a regular expression. It only replace 1:1 the string "<*>". How can I use the replace function in VBA like I do in Excel?

Upvotes: 2

Views: 1101

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627390

To search and replace all cells in the active sheet, you need to use something like:

Cells.Replace What:="<*>", Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

Note that you can indicate the cell directly in the beginning: Cells(2,1). (to only replace in the A2 cell.

Upvotes: 4

Related Questions