lpau001
lpau001

Reputation: 97

Excel VBA Replace Character

I tried looking around for this particular problem, but couldn't find it.

I am trying to replace an assortment of characters in a string.

I tried looping through the characters using their character codes, but my code will ?randomly? delete the entire string instead of just the special characters. (basically I just want the letters and numbers from the string) EG. ABC-3.3%H14T-6 I would just want ABC33H14T6

What is strange about this (to me) is that my code will delete the string on a random character, it's not always chr(41) or whatever, it changes each time I run the code.. is it maybe a formatting issue?

For Char = 33 To 47
Sheets("Sheet1").Cells(FRow, 44).Replace What:=Chr(Char), Replacement:="", LookAt:=xlPart
Next Char

I would give you the bulk of my code, but it is work-sensitive.

Any advice would be appreciated!

Thanks guys.

Upvotes: 1

Views: 726

Answers (1)

lpau001
lpau001

Reputation: 97

I'm dumb Chr(42) = *

which would replace everything. durr

Upvotes: 5

Related Questions