Macro VBA to Remove Characters in String of Text

July 25, 2009 by vba excel
Filed under: Excel Vba 
Sponsor

Excel Macro VBA to Remove Characters in String of Text [Q]
I need to make an excel macro vba to remove the 7th character in a string of text if the first 6 letters match the specified criteria. But I don’t know the best way to handle…

This is what I want to do:
If the first 6 characters of a2=”Albany”, then delete the next character
(which in this case is “,”).

If the above isn’t true…then continue on with the remainder of the macro.

And continue to the next row.

Excel Macro VBA to Remove Characters in String of Text [A]
For each microsoft excel cell in selection :
if instr(1,cell.Value,”Albany”,VbTextCompare) = 1 then
cell.Value = left(cell.Value,6) & Mid(cell.value,8)
end if
Next

This would remove rich text formatting.

if you want it to be a case sensitive match change vbTextCompare to
vbBinaryCompare

You can speed it up by using the find method of the range object and only
going to cells that contain Albany. Look at Excel VBA help at the FindNext
sample code.

  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • Live
  • MisterWong
  • Propeller
  • StumbleUpon
  • Technorati
  • TwitThis
  • YahooMyWeb
  • Print this article!

Rate This Tips:

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...


Incoming excel search terms

vba remove characters from string,excel vba remove character from string,vba remove string from string,vba replace characters in a string,excel vba remove text from string,excel vba replace string,vba string remove,excel vba replace characters in a string,remove string from string vba,remove text from string vba,vba remove character from string,vba remove letters,vba replace character in string,1,excel remove characters from string,excel vba remove characters,excel vba remove string from string,how to delete a specific character from an entire spreadsheet,vba excel remove character from string,vba instring,vba string,vba string remove character,remove characters from string vba,excel macro replace character,excel vba remove characters from string,excel vba string,vba remove letters from string,vba to delete some alphabatical characters in a cell,vba trim characters from string,excel macro remove letters from string,excel macro to remove characters,excel remove string,excel replace character in string,excel vba delete first character,excel vba remove character,excel vba remove letters from string,excel vba remove spaces from string,macro-vba,remove characters excel vba,remove characters from string excel vba,vba remove character,vba remove from string,,2,excel delete characters in string,excel instring,excel macr search for a character in string,excel macro remove first character,excel macro replace char in string,excel macro search character



Related Excel Tips

Comments

3 Comments on Macro VBA to Remove Characters in String of Text

  1. Insun Yang on Sat, 24th Oct 2009 11:34 pm
  2. I have download stock tickers. However after ticker “US Equity” follows in the same cell. I need to delete “Us Equity” but threr are thousands of them. How can I do?

    Thank you,

  3. Herb Lightle on Tue, 15th Dec 2009 1:59 am
  4. After transferring data from old computer - can no longer change formats in excel?

  5. Herb Lightle on Tue, 15th Dec 2009 2:12 am
  6. I use lots of macros in my Excel spread sheets, never have had a problem until I bought a new computer. Help! Commas instead of periods! Formulas do not recognize commas.
    Dates do not enter correctly, basically formatting no longer works!

    Herb

Have another excel answer or questions for this problem ?
Feel free to post it here..