Probably some of the values are not found. Try adding a condition:
If Not rngFound Is Nothing Then
rngFound.Interior.Color = vbBlue
End If
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to see if the Part Number in column AA exists in column U. If so I want column AB to say YES, and I want excel to find that particular part number in column U, wherever it may be, and highlight it. I copied some values from column U onto column AA to see if its working fine and it is but when the code encounters values that are typed I get an Object variable or with block variable not set.
Code:
` Dim x As Integer
Application.ScreenUpdating = False
' Set numrows = number of rows of data.
NumRows = Range("AB1", Range("AB1").End(xlDown)).Rows.Count
' Select cell a1.
Range("AB1").Select
Dim rngS As Range
Dim rngFound As Range
Set rngS = Cells.Range("U:U")
' Establish "For" loop to loop "numrows" number of times.
For x = 1 To NumRows
Debug.Print (x)
Debug.Print (Cells(x, 28))
If Cells(x, 28) = "YES" Then
Debug.Print (Cells(x, 27))
Set rngFound = rngS.Find(Cells(x, 27), , xlFormulas, xlWhole)
' Debug.Print (highlighted_value)
' Debug.Print (highlighted_value.Column)
' Debug.Print (highlighted_value.Row)
rngFound.Interior.Color = vbBlue
'
'=NOT(ISERROR(VLOOKUP(TRIM(U21:U36),TRIM($AA$2:$AA$12),1,FALSE)))
'=NOT(ISERROR(VLOOKUP(TRIM(U4:U17),TRIM($AA$2:$AA$12),1,FALSE)))
' Debug.Print (highlighted_value)
'find cell value in column U
End If
' Insert your code here.
' Selects cell down 1 row from active cell.
ActiveCell.Offset(1, 0).Select
Next
Application.ScreenUpdating = True
`
Probably some of the values are not found. Try adding a condition:
If Not rngFound Is Nothing Then
rngFound.Interior.Color = vbBlue
End If