Code: Select all
Set srch = rng4a.Offset(0, 1).Find(What:=ws1b.Range("T" & row), LookIn:=xlValues, LookAt:=xlWhole)
If Not srch Is Nothing Then
srch.Offset(0, -14).Resize(, 6).Copy Destination:=ws1b.Range("G" & row)
ElseIf wb4.Worksheets.Count > 1 And wb4.Worksheets.Count < 3 Then
Set srch = rng4b.Offset(0, 1).Find(What:=ws1b.Range("T" & row), LookIn:=xlValues, LookAt:=xlWhole)
If Not srch Is Nothing Then
srch.Offset(0, -14).Resize(, 6).Copy Destination:=ws1b.Range("G" & row)
End If
ElseIf wb4.Worksheets.Count > 2 Then
Set srch = rng4c.Offset(0, 1).Find(What:=ws1b.Range("T" & row), LookIn:=xlValues, LookAt:=xlWhole)
If Not srch Is Nothing Then
srch.Offset(0, -14).Resize(, 6).Copy Destination:=ws1b.Range("G" & row)
End If
Else
Set srch = rng6a.Offset(0, 1).Find(What:=ws1b.Range("T" & row), LookIn:=xlValues, LookAt:=xlWhole)
If Not srch Is Nothing Then
srch.Offset(0, -14).Resize(, 6).Copy Destination:=ws1b.Range("G" & row)
End If
End If
rng4a (ws4a)
rng4b (ws4b will not always exist)
rng4c (ws4c will not always exist)
rng6a (ws6a)
but cease the search at the earliest opportunity. Help......
wb4 can contain 1, 2 or 3 worksheets, hence my attempt to establish the worksheet count to ascertain if the 2nd and 3rd worksheets exist before searching.