D
Don
OK Rocky.....MSN let me back on finally....here's what I came up
with...Tested it some but would advise you to test and re-test it...use
copies of your WB just in case.
This new code should do what you requested, including some things that will
make it more OP friendly. It will also keep track of where you stopped. The
MsgBox's and InputBox's are pretty self-explanatory.
First: Create a new WS and name it "WrkSht" without the quotes.
Second: On this new WS:
In Cell A1 enter "1"
In Cell A2 enter "A"
In Cell A3 enter "ABC"
In Cell A4 enter "47-"
All of the above without the quotes.
Input the following code into a new Module:
Option Compare Text
Option Explicit
Sub FindReplace()
Dim c As Range
Dim MySearchValue As String
Dim MyString As String
Dim ReplaceWith As String
Dim MyCol As String
Dim Rge As Range
Dim i As Long
Dim LastRow, LstRowUsed As Long
Dim Response, RowDir, PrevEnt As String
On Error Resume Next
i = 0
PrevEnt = _
MsgBox("DO YOU WANT TO USE PREVIOUS COLUMN USED: COLUMN: " _
& Sheets("WrkSht").Range("A2"), vbYesNoCancel + vbInformation)
If PrevEnt = vbCancel Then Exit Sub
If PrevEnt = vbYes Then
MyCol = Sheets("WrkSht").Range("A2")
End If
If PrevEnt = vbNo Then _
MyCol = InputBox("WHAT COLUMN DO YOU WANT TO SEARCH IN?")
Sheets("WrkSht").Range("A2") = MyCol
If MyCol = "" Then
Exit Sub
End If
With ActiveSheet
LastRow = .Cells(.Rows.Count, MyCol).End(xlUp).Row
End With
PrevEnt = _
MsgBox("WOULD YOU LIKE TO USE THE PREVIOUS SEARCH STRING USED: " _
& Sheets("wrksht").Range("A3"), vbYesNoCancel)
If PrevEnt = vbCancel Then
Exit Sub
End If
If PrevEnt = vbNo Then
MyString = InputBox("WHAT SEARCHSTRING DO YOU WANT TO USE?")
Sheets("WrkSht").Range("A3") = MyString
If MyString = "" Then Exit Sub
Else
MyString = Sheets("WrkSht").Range("A3")
End If
PrevEnt = MsgBox _
("WOULD YOU LIKE TO USE THE PREVIOUS STRING AS THE ADD FACTOR: " _
& Sheets("wrksht").Range("A4"), vbYesNoCancel)
If PrevEnt = vbCancel Then
Exit Sub
End If
If PrevEnt = vbNo Then
ReplaceWith = InputBox("WHAT WOULD YOU LIKE TO ADD?")
Sheets("WrkSht").Range("A4") = ReplaceWith
If MyString = "" Then Exit Sub
Else
ReplaceWith = Sheets("WrkSht").Range("A4")
End If
RowDir = _
MsgBox("WOULD YOU LIKE TO START WHERE YOU LEFT OFF?", _
vbYesNoCancel + vbInformation)
If RowDir = vbCancel Then Exit Sub
If RowDir = vbNo Then
i = InputBox("WHICH ROW WOULD YOU LIKE TO START ON?")
Sheets("WrkSht").Range("A1") = i
If i > 0 Then
GoTo Cont
Exit Sub
End If
Else
i = Sheets("WrkSht").Range("A1")
End If
Cont:
Set Rge = Range(MyCol & i & ":" & MyCol & LastRow)
For Each c In Rge
MySearchValue = InStr(c, MyString)
If (Not IsNull(MySearchValue)) And (MySearchValue > 0) Then
Range(MyCol & i).Select
Response = MsgBox("Is This One To Addend?", vbYesNoCancel _
+ vbInformation)
If Response = vbYes Then GoTo Add
If Response = vbCancel Then
Exit Sub
End If
If Response = vbNo Then GoTo Rep
End If
Rep:
i = i + 1
Sheets("WrkSht").Range("A1") = i
Next c
Exit Sub
Add:
Range(MyCol & i).Offset(0, 1).Value = ReplaceWith & _
Range(MyCol & i).Offset(0, 1).Value
GoTo Rep
End Sub
Make sure you've selected the Sheet that has the data you want to search.
(didn't put this in code as I wasn't sure what the name of your sheet was)
This could probably get cleaned up a bit, but I think it'll do what you've
asked for.
Let me know......
Don
with...Tested it some but would advise you to test and re-test it...use
copies of your WB just in case.
This new code should do what you requested, including some things that will
make it more OP friendly. It will also keep track of where you stopped. The
MsgBox's and InputBox's are pretty self-explanatory.
First: Create a new WS and name it "WrkSht" without the quotes.
Second: On this new WS:
In Cell A1 enter "1"
In Cell A2 enter "A"
In Cell A3 enter "ABC"
In Cell A4 enter "47-"
All of the above without the quotes.
Input the following code into a new Module:
Option Compare Text
Option Explicit
Sub FindReplace()
Dim c As Range
Dim MySearchValue As String
Dim MyString As String
Dim ReplaceWith As String
Dim MyCol As String
Dim Rge As Range
Dim i As Long
Dim LastRow, LstRowUsed As Long
Dim Response, RowDir, PrevEnt As String
On Error Resume Next
i = 0
PrevEnt = _
MsgBox("DO YOU WANT TO USE PREVIOUS COLUMN USED: COLUMN: " _
& Sheets("WrkSht").Range("A2"), vbYesNoCancel + vbInformation)
If PrevEnt = vbCancel Then Exit Sub
If PrevEnt = vbYes Then
MyCol = Sheets("WrkSht").Range("A2")
End If
If PrevEnt = vbNo Then _
MyCol = InputBox("WHAT COLUMN DO YOU WANT TO SEARCH IN?")
Sheets("WrkSht").Range("A2") = MyCol
If MyCol = "" Then
Exit Sub
End If
With ActiveSheet
LastRow = .Cells(.Rows.Count, MyCol).End(xlUp).Row
End With
PrevEnt = _
MsgBox("WOULD YOU LIKE TO USE THE PREVIOUS SEARCH STRING USED: " _
& Sheets("wrksht").Range("A3"), vbYesNoCancel)
If PrevEnt = vbCancel Then
Exit Sub
End If
If PrevEnt = vbNo Then
MyString = InputBox("WHAT SEARCHSTRING DO YOU WANT TO USE?")
Sheets("WrkSht").Range("A3") = MyString
If MyString = "" Then Exit Sub
Else
MyString = Sheets("WrkSht").Range("A3")
End If
PrevEnt = MsgBox _
("WOULD YOU LIKE TO USE THE PREVIOUS STRING AS THE ADD FACTOR: " _
& Sheets("wrksht").Range("A4"), vbYesNoCancel)
If PrevEnt = vbCancel Then
Exit Sub
End If
If PrevEnt = vbNo Then
ReplaceWith = InputBox("WHAT WOULD YOU LIKE TO ADD?")
Sheets("WrkSht").Range("A4") = ReplaceWith
If MyString = "" Then Exit Sub
Else
ReplaceWith = Sheets("WrkSht").Range("A4")
End If
RowDir = _
MsgBox("WOULD YOU LIKE TO START WHERE YOU LEFT OFF?", _
vbYesNoCancel + vbInformation)
If RowDir = vbCancel Then Exit Sub
If RowDir = vbNo Then
i = InputBox("WHICH ROW WOULD YOU LIKE TO START ON?")
Sheets("WrkSht").Range("A1") = i
If i > 0 Then
GoTo Cont
Exit Sub
End If
Else
i = Sheets("WrkSht").Range("A1")
End If
Cont:
Set Rge = Range(MyCol & i & ":" & MyCol & LastRow)
For Each c In Rge
MySearchValue = InStr(c, MyString)
If (Not IsNull(MySearchValue)) And (MySearchValue > 0) Then
Range(MyCol & i).Select
Response = MsgBox("Is This One To Addend?", vbYesNoCancel _
+ vbInformation)
If Response = vbYes Then GoTo Add
If Response = vbCancel Then
Exit Sub
End If
If Response = vbNo Then GoTo Rep
End If
Rep:
i = i + 1
Sheets("WrkSht").Range("A1") = i
Next c
Exit Sub
Add:
Range(MyCol & i).Offset(0, 1).Value = ReplaceWith & _
Range(MyCol & i).Offset(0, 1).Value
GoTo Rep
End Sub
Make sure you've selected the Sheet that has the data you want to search.
(didn't put this in code as I wasn't sure what the name of your sheet was)
This could probably get cleaned up a bit, but I think it'll do what you've
asked for.
Let me know......
Don