Question : VBA Find function Run time error 91, Object Variable or With block Variable not set

Hi Experts

The code below has an array of names, "ArrayName" which is from "NoPiceNames" rangenamed from the excel sheet.
I would like to scroll through this array and on each iteration search the worksheet "RedAmberGreen" to see if any of the names from
the array are on there.

Ideally I would like something to happen on the worksheet "RedAmberGreen" to verify that one of the Names has been found i.e like
a cell colour becoming red.

Please help, this is driving me crazy.  Thanks for your time

Sub Prototypefind()

Dim i As Integer
Dim NoPriceNames As Range
Dim ArrayName As Variant
Dim TempString As String
Dim RedAmberGreen As Worksheet
Dim LeftTemp As String
Dim Found As Boolean

ArrayName = Range("NoPriceNames")

Worksheets("RedAmberGreen").Select

For i = 1 To UBound(ArrayName)

TempString = ArrayName(i, 1)
LeftTemp = Left(TempString, 4)


Range("C:O").Select
 Found = Cells.Find(What:=LeftTemp, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
       :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
       False, SearchFormat:=False).Activate
 
Next i
End Sub






Answer : VBA Find function Run time error 91, Object Variable or With block Variable not set

How about this

It searches the range of interest (withou activating the sheet)
Highlights thefound cell red, and tells you where it is

Cheers

Dave
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
ub Prototypefind()
 
Dim i As Integer
Dim ArrayName As Variant
Dim TempString As String
    Dim ws As Worksheet
Dim LeftTemp As String
    Dim rng1 As Range
 
ArrayName = Range("NoPriceNames")
Set ws = Worksheets("RedAmberGreen")
 
For i = 1 To UBound(ArrayName)
        TempString = ArrayName(i, 1)
        LeftTemp = Left(TempString, 4)
        Set rng1 = ws.Columns("C:O").Find(LeftTemp, , xlFormulas, xlPart, xlByRows, xlNext)
        If Not rng1 Is Nothing Then
        rng1.Interior.Color = vbRed
        MsgBox "found " & LeftTemp & " in " & rng1.Parent.Name & " " & rng1.Address(False, False)
        End If
    Next i
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us