Apologies wasnt aware you could hover or how to code out. Hopefully the below is more useful to you.
The code I have now is as follows:
Option Explicit
Sub FindReplaceAcrossWB()
Dim WS As Worksheet
Dim iWS As Worksheet
Dim A As Long
Dim LastRow As Long
Dim C As Range, FirstAddress As String
Dim SrchAry(1 To 2, 1 To 2) As String
'Define array for Find/Replace
SrchAry(1, 1) = Sheets("Macro").Range("H8").Value
SrchAry(1, 2) = Sheets("Macro").Range("J8").Value
SrchAry(2, 1) = Sheets("Macro").Range("H15").Value
SrchAry(2, 2) = Sheets("Macro").Range("J15").Value
'Iterate all worksheets.
For Each iWS In Worksheets
'Work with each sheet based on it's name.
Select Case iWS.Name
'Names of worksheets to skip.
Case "Macro" ', "Second WS to skip"
Case Else 'all other worksheets to search.
'Define ws as object
Set WS = Worksheets(iWS.Name)
'With iWS
With iWS
'Determine lastrow of object WS.
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'Define range to search.
With .Range("A1:A" & LastRow)
'Iterate the array of search items.
For A = 1 To UBound(SrchAry)
'Make sure the element isn't empty.
If SrchAry(A, 1) <> "" Then
'Search, looking in values.
Set C = .Find(SrchAry(A, 1), LookIn:=xlValues)
'We found something
If Not C Is Nothing Then
'Record the first found address.
FirstAddress = C.Address
Do
'Replace the value.
C.Value = SrchAry(A, 2)
'Keep searching
Set C = .FindNext(C)
'Keep looking until conditions met.
Loop While Not C Is Nothing And C.Address <> FirstAddress
End If
End If
Next
End With
End With
End Select
Next
End Sub
In this line:
'Define ws as object
Set WS = Worksheets(iWS.Name)
The value gives correct names of my worksheets and as I press F8 it changes as it cycles through.
In this line:
If SrchAry(A, 1) <> "" Then
'Search, looking in values.
Set C = .Find(SrchAry(A, 1), LookIn:=xlValues)
'We found something
The value shows as <Subscript out of range> for both SrchAry.
Set C = .Find(SrchAry(A, 1), LookIn:=xlValues)
'We found something
If Not C Is Nothing Then
'Record the first found address.
FirstAddress = C.Address
Do
'Replace the value.
C.Value = SrchAry(A, 2)
The C in the first line = Nothing. And the C.Address = <Object variable or With block variable not set>.
'Replace the value.
C.Value = SrchAry(A, 2)
'Keep searching
Set C = .FindNext(C)
And SrchAry(A, 2) = subscript out of range.
And
This value also = Nothing.
Hope that helps and thanks again.
Bookmarks