Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default VBA Help Please

The code below looks for a text string in column D: "AV1 Swb"
then offsets to a desired position and adds text: "Switchboard"

I need to make a modification to this, but am not sure how. Instead of
offsetting text, I want to replace the entire entry that contains "AV1 Swb"
with "Switchboard".

Any help you can provide would be appreciated.

Here is the code I have today in a large macro:

Set rng = Columns(4).Find(what:="AV1 Swb", _
after:=Range("D1"), LookIn:=xlFormulas, _
lookat:=xlPart, searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
fAddr = rng.Address
Do
rng.Offset(0, -1).Value = "Switchboard"
Set rng = Columns(4).FindNext(rng)
Loop While rng.Address < fAddr
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA Help Please

Untested:

Do
rng.Value = "Switchboard"
Set rng = Columns(4).FindNext(rng)
if rng is nothing then exit do
Loop

But I think I would drop the loop and just do an edit|replace in code:

Columns("D:D").Replace What:="*AV1 Swb*", Replacement:="Switchboard", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False



Scott Wagner wrote:

The code below looks for a text string in column D: "AV1 Swb"
then offsets to a desired position and adds text: "Switchboard"

I need to make a modification to this, but am not sure how. Instead of
offsetting text, I want to replace the entire entry that contains "AV1 Swb"
with "Switchboard".

Any help you can provide would be appreciated.

Here is the code I have today in a large macro:

Set rng = Columns(4).Find(what:="AV1 Swb", _
after:=Range("D1"), LookIn:=xlFormulas, _
lookat:=xlPart, searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
fAddr = rng.Address
Do
rng.Offset(0, -1).Value = "Switchboard"
Set rng = Columns(4).FindNext(rng)
Loop While rng.Address < fAddr
End If


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default VBA Help Please

Thank you sir! That worked perfectly. (as always)
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"