Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find/Replace String


I've got a workbook with two sheets in it. The first sheet name
"Macro" has a lot of data on it consisting or erroneou
characters/statements like "as above" and ". The second sheet is name
"Definitions" which consists of a list of these erronreou
charactes/statements.

The macro I use goes to Definitions and sets the first cell value as
string variable. The macro then goes to Macro and uses the fin
function to find the String variable, isolate ONLY that cell and cop
paste the contents of the cell above into it - this is looped until al
instances are removed. Once that happens the macro goes back t
Definitions, goes down the list to the next entry and repeats th
process.

Only two of my definitions work, where at the end of the second i
causes an error. I'm not sure how I can correct this, so I woul
appreciate any help. My code is as follows:


Code
-------------------

Sub RemoveInvalidChars()
On Error GoTo NextDefinition
Dim strCellAddress, strDefinition As String

Application.DisplayAlerts = False

Sheets("Definitions").Select
Range("A1").Select
If ActiveCell = "" Then Exit Sub Else
strDefinition = ActiveCell.Value
GoTo RunLoop

RunLoop:
Do
Sheets("Macro").Select
Cells.Select ' Selects all the cells on the sheet
Selection.Find(What:=strDefinition, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate ' Finds the Quote
strCellAddress = ActiveCell.Address ' Sets the ActiveCell as the strCellAddress value
Range([strCellAddress]).Select ' Goes to the previous set ranged cell
Selection.Offset(-1, 0).Select ' Shifts Cell Outline to the cell above
Selection.Copy ' Copy value from cell
Selection.Offset(1, 0).Select ' Shift Cell Outline down to quote "
ActiveSheet.Paste ' Pastes copied value
Loop
Exit Sub

NextDefinition:
Application.CutCopyMode = False
Sheets("Definitions").Select
Selection.Offset(1, 0).Select
If ActiveCell = vbNullString Then GoTo ExitSubRoutine Else
strDefinition = ActiveCell.Value
GoTo RunLoop
Exit Sub

ExitSubRoutine:
Exit Sub

End Sub

-------------------

--
MysticalNoma
-----------------------------------------------------------------------
MysticalNomad's Profile: http://www.excelforum.com/member.php...fo&userid=1354
View this thread: http://www.excelforum.com/showthread.php?threadid=27274

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
Find & Replace a string contained in a link Matt from GVA Excel Discussion (Misc queries) 3 September 5th 06 01:24 PM
How do I replace last numeric string from a alphanumeric string? Christy Excel Discussion (Misc queries) 3 August 11th 06 12:17 AM
Find and replace part of a text string [email protected] Excel Discussion (Misc queries) 2 July 10th 06 10:34 PM
find and replace - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM
Excel - Find & Replace text in a string bklim Excel Worksheet Functions 1 June 14th 05 06:42 AM


All times are GMT +1. The time now is 11:30 AM.

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"