View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
MysticalNomad MysticalNomad is offline
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