Hi Tom,
As the titles are in Proper-case (not in lower-case), I took out the
lCase to make the line just {If (cell.Value) = "Total" Then} for an
exact match. How would you alter this so that it is not case-sensitive
and entering "total" would still be valid?
Really need your help with the other 2 codes:
Sub ReplaceOtherStrings()
I've tried matching the lower-case/upper-case exact word but it takes no
action. I'm unsure of the end result with what Trim ans2 does as I
don't need it to be case-sensitive and also what;
{If InStr(1, ans1, "Total", vbTextCompare) = 1 Then} does
because "Total" would have been completely replaced through the Sub
ReplaceTotal() code already.
I need to make replacements of titles that is listed between 2 empty
cells. The search is based on locating "Total Operating Expenses"
first. Directly above "Total Operating Expenses" is an empty cell. The
list of titles to be replaced would then be located directly above it.
The word to replace is based on an input box of InputBox("Enter
Replacement Term").
I think that's what the ReplaceOtherStrings() was meant to do but I
really need your help.
Sub ReplaceSpecifiedWordWithSpecifiedWord()
errors at the first line; ans1 = InputBox("Enter Search term") is
highlighted. We could come back to this later.
So far this following code works very nicely. The Sub
ReplaceOtherStrings() would then be an extension of this code.
Sub ReplaceTotal()
Dim s As String, cell As Range, rng As Range
Dim i As Long, ans As Long, s1 As String
Set rng = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
For Each cell In rng
If (cell.Value) = "Total" Then
i = cell.Row - 2
Do Until Len(Trim(Cells(i, 1))) = 0
i = i - 1
Loop
cell.Select
s = "[Total] will be replaced by " & Cells(i + 1, 1).Value &
vbNewLine _
& vbNewLine _
& "Yes: Continue" & vbNewLine _
& "No: Do Not Replace" & vbNewLine _
& "Cancel: Override to Input Alternate Title"
ans = MsgBox(s, vbYesNoCancel, "Select an Option")
Select Case ans
Case vbYes
cell.Value = Cells(i + 1, 1).Value
Case vbCancel
s1 = InputBox("Enter Alternate Title to Replace?", _
"Enter Replacement", Cells(i + 1, 1).Value)
If Len(Trim(s1)) 0 Then
cell.Value = s1
End If
End Select
End If
Next
End Sub
As always, I greatly appreciate your help.
Thanks in advance,
Ricky
*** Sent via Developersdex
http://www.developersdex.com ***