RE: Help with Search and Replace
From: stanshoe (stanshoe_at_discussions.microsoft.com)
Date: 11/29/04
- Next message: Bob Phillips: "Re: Checking & installing references as part of on_open"
- Previous message: Bob Phillips: "Re: Checking & installing references as part of on_open"
- In reply to: mak: "Help with Search and Replace"
- Messages sorted by: [ date ] [ thread ]
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
>
- Next message: Bob Phillips: "Re: Checking & installing references as part of on_open"
- Previous message: Bob Phillips: "Re: Checking & installing references as part of on_open"
- In reply to: mak: "Help with Search and Replace"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|