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,excel vba replace characters in a string,vba remove string from string,excel vba remove text from string,vba replace characters in a string,excel vba trim,excel remove characters from string,vba excel remove character from string,vba string remove,vba remove character from string,excel vba remove string from string,excel vba replace string,remove string from string vba,remove characters from string vba,vba remove letters from string,,excel macro replace character,remove text from string vba,vba excel replace character in string,vba instring,vba string,vba trim characters from string,excel vba remove characters,excel vba remove characters from string,macro to strip out text,vba remove,vba remove letters,vba replace character in string,vba string remove character,excel delete characters in string,excel vba delete text,excel vba remove characters from a string,excel vba trim string,how to remove a character from a string in macro,vba characters,0,1,excel macro to remove characters,excel vba remove spaces from string,excel vba replace characters string,excel vba string,how to delete a specific character from an entire spreadsheet,mss,remove characters from string excel,string vba,vba remove first character in string,excel instring,excel macro delete characters,excel macro replace characters in string



Related Excel Tips

Comments

4 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

  7. Vladislav on Thu, 1st Apr 2010 12:08 pm
  8. Dear Macros Guru,
    Please help me to solve the problem.

    asdssf fdfdfdf 5ff N30 just to extract N30
    sffsf sdfsdffff 5ddd N50 (K) just to extract N50
    ssfs Tddd 150sd N30 just to extract N30

    I have list of such strings as above.
    I have to get from string just N+number

    Best regards,

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