Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with search and Replace


I needed to search a cell for "CR" and change it to "Crescent". Problem
was if the the cell contained "Crestlawn CR" it would change it to
"CRESCENTestlawn CRESCENT". I found away around it by adding my name
"malcolmbrown" to the end of each cell and then searching for
CRMALCOLMBROWN". IT works but there has to be a better way.

here is part of my routine so far

'Loops adding MALCOLMBROWN at the end of each address
Range("A1").Select
Dim p As Integer
intRowCount = Range("A1").CurrentRegion.Rows.Count
For p = 1 To intRowCount
'Adds MALCOLMBROWN onto the end of the address
ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0,
1).Value & "MALCOLMBROWN"
ActiveCell.Offset(1, 0).Select
Next p
'Replaces CRMALCOLMBROWN with crescent and deletes
MALCOLMBROWN
Columns("B:B").Select
Selection.Replace What:="CRMALCOLMBROWN",
Replacement:="CRESCENT", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="MALCOLMBROWN", Replacement:="",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False


--
icdoo
------------------------------------------------------------------------
icdoo's Profile: http://www.excelforum.com/member.php...o&userid=27342
View this thread: http://www.excelforum.com/showthread...hreadid=468512

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Help with search and Replace

Try replacing in your code :=xlPart with :=xlWhole

RBS


"icdoo" wrote in
message ...

I needed to search a cell for "CR" and change it to "Crescent". Problem
was if the the cell contained "Crestlawn CR" it would change it to
"CRESCENTestlawn CRESCENT". I found away around it by adding my name
"malcolmbrown" to the end of each cell and then searching for
CRMALCOLMBROWN". IT works but there has to be a better way.

here is part of my routine so far

'Loops adding MALCOLMBROWN at the end of each address
Range("A1").Select
Dim p As Integer
intRowCount = Range("A1").CurrentRegion.Rows.Count
For p = 1 To intRowCount
'Adds MALCOLMBROWN onto the end of the address
ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0,
1).Value & "MALCOLMBROWN"
ActiveCell.Offset(1, 0).Select
Next p
'Replaces CRMALCOLMBROWN with crescent and deletes
MALCOLMBROWN
Columns("B:B").Select
Selection.Replace What:="CRMALCOLMBROWN",
Replacement:="CRESCENT", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="MALCOLMBROWN", Replacement:="",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False


--
icdoo
------------------------------------------------------------------------
icdoo's Profile:
http://www.excelforum.com/member.php...o&userid=27342
View this thread: http://www.excelforum.com/showthread...hreadid=468512


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with search and Replace

But that means you're looking at the whole cell--not whole word (like MSWord).

RB Smissaert wrote:

Try replacing in your code :=xlPart with :=xlWhole

RBS

"icdoo" wrote in
message ...

I needed to search a cell for "CR" and change it to "Crescent". Problem
was if the the cell contained "Crestlawn CR" it would change it to
"CRESCENTestlawn CRESCENT". I found away around it by adding my name
"malcolmbrown" to the end of each cell and then searching for
CRMALCOLMBROWN". IT works but there has to be a better way.

here is part of my routine so far

'Loops adding MALCOLMBROWN at the end of each address
Range("A1").Select
Dim p As Integer
intRowCount = Range("A1").CurrentRegion.Rows.Count
For p = 1 To intRowCount
'Adds MALCOLMBROWN onto the end of the address
ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0,
1).Value & "MALCOLMBROWN"
ActiveCell.Offset(1, 0).Select
Next p
'Replaces CRMALCOLMBROWN with crescent and deletes
MALCOLMBROWN
Columns("B:B").Select
Selection.Replace What:="CRMALCOLMBROWN",
Replacement:="CRESCENT", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="MALCOLMBROWN", Replacement:="",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False


--
icdoo
------------------------------------------------------------------------
icdoo's Profile:
http://www.excelforum.com/member.php...o&userid=27342
View this thread: http://www.excelforum.com/showthread...hreadid=468512


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Help with search and Replace

OK, the problem wasn't that well described.
I thought he was trying to replace CR if that was the only text in the cell.

RBS

"Dave Peterson" wrote in message
...
But that means you're looking at the whole cell--not whole word (like
MSWord).

RB Smissaert wrote:

Try replacing in your code :=xlPart with :=xlWhole

RBS

"icdoo" wrote in
message ...

I needed to search a cell for "CR" and change it to "Crescent". Problem
was if the the cell contained "Crestlawn CR" it would change it to
"CRESCENTestlawn CRESCENT". I found away around it by adding my name
"malcolmbrown" to the end of each cell and then searching for
CRMALCOLMBROWN". IT works but there has to be a better way.

here is part of my routine so far

'Loops adding MALCOLMBROWN at the end of each address
Range("A1").Select
Dim p As Integer
intRowCount = Range("A1").CurrentRegion.Rows.Count
For p = 1 To intRowCount
'Adds MALCOLMBROWN onto the end of the address
ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0,
1).Value & "MALCOLMBROWN"
ActiveCell.Offset(1, 0).Select
Next p
'Replaces CRMALCOLMBROWN with crescent and deletes
MALCOLMBROWN
Columns("B:B").Select
Selection.Replace What:="CRMALCOLMBROWN",
Replacement:="CRESCENT", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="MALCOLMBROWN", Replacement:="",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False


--
icdoo
------------------------------------------------------------------------
icdoo's Profile:
http://www.excelforum.com/member.php...o&userid=27342
View this thread:
http://www.excelforum.com/showthread...hreadid=468512


--

Dave Peterson


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with search and Replace

Ahhh.

RB Smissaert wrote:

OK, the problem wasn't that well described.
I thought he was trying to replace CR if that was the only text in the cell.

RBS

"Dave Peterson" wrote in message
...
But that means you're looking at the whole cell--not whole word (like
MSWord).

RB Smissaert wrote:

Try replacing in your code :=xlPart with :=xlWhole

RBS

"icdoo" wrote in
message ...

I needed to search a cell for "CR" and change it to "Crescent". Problem
was if the the cell contained "Crestlawn CR" it would change it to
"CRESCENTestlawn CRESCENT". I found away around it by adding my name
"malcolmbrown" to the end of each cell and then searching for
CRMALCOLMBROWN". IT works but there has to be a better way.

here is part of my routine so far

'Loops adding MALCOLMBROWN at the end of each address
Range("A1").Select
Dim p As Integer
intRowCount = Range("A1").CurrentRegion.Rows.Count
For p = 1 To intRowCount
'Adds MALCOLMBROWN onto the end of the address
ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0,
1).Value & "MALCOLMBROWN"
ActiveCell.Offset(1, 0).Select
Next p
'Replaces CRMALCOLMBROWN with crescent and deletes
MALCOLMBROWN
Columns("B:B").Select
Selection.Replace What:="CRMALCOLMBROWN",
Replacement:="CRESCENT", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="MALCOLMBROWN", Replacement:="",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False


--
icdoo
------------------------------------------------------------------------
icdoo's Profile:
http://www.excelforum.com/member.php...o&userid=27342
View this thread:
http://www.excelforum.com/showthread...hreadid=468512


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with search and Replace

It looks like you want to replace " CR" at the end of each value in column B.

If that's the case, maybe something like:

Option Explicit
Sub testme01()

Dim myRng As Range
Dim myFStr As String
Dim myTStr As String
Dim FoundCell As Range

With Worksheets("sheet1")
Set myRng = .Range("b:b")
End With

myFStr = " CR"
myTStr = " Crescent"

With myRng
Do
Set FoundCell = .Cells.Find(What:="*" & myFStr, _
After:=.Cells(.Cells.Count), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

If FoundCell Is Nothing Then
Exit Do 'we're done
End If

FoundCell.Value _
= Left(FoundCell.Value, _
Len(FoundCell.Value) - Len(myFStr)) & myTStr
Loop
End With

End Sub

It looks for "* CR" in the whole cell. That means that the cell has to end with
spaceCR. Once we find it, we change it and keep looking.




icdoo wrote:

I needed to search a cell for "CR" and change it to "Crescent". Problem
was if the the cell contained "Crestlawn CR" it would change it to
"CRESCENTestlawn CRESCENT". I found away around it by adding my name
"malcolmbrown" to the end of each cell and then searching for
CRMALCOLMBROWN". IT works but there has to be a better way.

here is part of my routine so far

'Loops adding MALCOLMBROWN at the end of each address
Range("A1").Select
Dim p As Integer
intRowCount = Range("A1").CurrentRegion.Rows.Count
For p = 1 To intRowCount
'Adds MALCOLMBROWN onto the end of the address
ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0,
1).Value & "MALCOLMBROWN"
ActiveCell.Offset(1, 0).Select
Next p
'Replaces CRMALCOLMBROWN with crescent and deletes
MALCOLMBROWN
Columns("B:B").Select
Selection.Replace What:="CRMALCOLMBROWN",
Replacement:="CRESCENT", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="MALCOLMBROWN", Replacement:="",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False

--
icdoo
------------------------------------------------------------------------
icdoo's Profile: http://www.excelforum.com/member.php...o&userid=27342
View this thread: http://www.excelforum.com/showthread...hreadid=468512


--

Dave Peterson
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
search and replace Timo Excel Discussion (Misc queries) 1 August 25th 09 06:06 PM
Search and Replace help hodeware Excel Programming 1 April 1st 05 01:45 AM
Search and replace This Guy Excel Worksheet Functions 0 January 5th 05 06:02 PM
search & replace Joe Excel Worksheet Functions 0 November 9th 04 02:55 PM
Search and Replace... Paul B[_7_] Excel Programming 0 October 1st 03 06:12 PM


All times are GMT +1. The time now is 04:00 PM.

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

About Us

"It's about Microsoft Excel"