RE: Help with Search and Replace

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: stanshoe (stanshoe_at_discussions.microsoft.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 15:09:05 -0800

If you are looking to replace one substring for another that is the same
length, you can use the "Mid" statement. Mid lets you designate the starting
position and the length of the string you want to work with. For example, if
I wanted to replace the substring "a" with the substring "b" if "a" appeared
as the third character in the string I could use.

    Dim strTest As String
    
    strTest = ActiveCell.Formula
    
    If Mid(strTest, 3, 1) = "a" Then
        Mid(strTest, 3, 1) = "b"
        ActiveCell.Formula = strTest
    End If

If the length of the substrings you are finding and replacing are different
lenghts, you should look at the VBA "Replace" function (not to be confused
with the Excel Text function - REPLACE)

Stan Shoemaker
Palo Alto, CA

"mak" wrote:

> Hello,
>
> I am looking for a simple method of searching through a range and replacing
> target specific characters within each cell / piece of data replacing or
> deleting them the old value with a new value. The key is that I want to
> specify the position of the character within the cell so I do not overwrite
> with the incorrect data.
>
> Thank you very much,
> Mark
>



Relevant Pages

  • Re: Will Dick Stay on as Bruces partner upon his return?
    ... and characters...it just doesn't fit the character. ... That's what really bugs me about Die Dan Die. ... replacing Hal but I know that one had a rather mixed reaction from ... continuity revisions in the past few years that current DCU history is ...
    (rec.arts.comics.dc.universe)
  • Re: How to return a variable length substring from a function ?
    ... I have a function that returns a variable length character substring. ... Depending on the input, the output is either 1 to 3 characters long. ... strings within fixed length strings. ...
    (comp.lang.fortran)
  • Re: Replace Formatting Styles in 3000 docs
    ... replacing text and it worked great, replacing text within 20 files in ... SrchAndRplInStry = False ... "Invalid Special Character." ... Word MVP web sitehttp://word.mvps.org ...
    (microsoft.public.word.vba.general)
  • Re: "The Office" plans to spotlight possible replacement bosses
    ... would bring a different character to the forefront of each episode. ... For instance, one episode this fall will highlight Andy, ... There will be more guest names added to the list; producers have been ... As for replacing Scott with a new manager, ...
    (rec.arts.tv)
  • Re: Help with Replace()
    ... but you're asking to return 1 character, from the 16th....this is the "-" letter, which is now null, hence the null string returned. ... The actual Variable StrToSearch was valued with the " " ... String expression containing sub string to replace. ... Substring being searched for. ...
    (microsoft.public.excel.programming)