Find and highlight based on criteria found

Knockoutpie

Board Regular
Joined
Sep 10, 2018
Messages
116
Office Version
  1. 365
Platform
  1. Windows
a few weeks ago @DanteAmor helped me with some code which would find "partnum" in a row on sheet Quote, select that value and search for it in sheet "export", if found it would offset by 24 columns and select the value..
It works very well, exactly what I needed!

VBA Code:
Sub test_Dam()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim f As Range
Dim i As Long, col1 As Long, col2 As Long, ini As Long
 
'set worksheet
Set sh1 = Sheets("Quote")
Set sh2 = Sheets("Export")
 
Set f = sh1.Cells.Find("Brand", , xlValues, xlPart, , , False)
If Not f Is Nothing Then
col1 = f.Column
ini = f.Row + 2
Set f = sh1.Cells.Find("Leadtime", , xlValues, xlPart, , , False)
If Not f Is Nothing Then
col2 = f.Column
For i = ini To sh1.Cells(Rows.Count, col1).End(3).Row
Set f = sh2.Cells.Find(sh1.Cells(i, col1).Value, , xlFormulas, xlPart, xlByRows, xlNext, False)
If Not f Is Nothing Then
sh1.Cells(i, col2).Value = f.Offset(0, 24).Value
End If
Next
End If
End If
End Sub

I'm trying to modify the code to find "brand" in row 3, on sheet1, move down 2 rows, select the value, and search for that value in column A in sheet "brands", if not found, highlight (in yellow) that selected value in Sheet1, and repeat until the end. I've modified it a little, and so far if it finds the result it changed it to "false" I get that it's a little redundant though and can be cut in half since i'm not offsetting or replacing values, just trying to highlight.

Maybe it would be easier to say if found, highlight in green? Because so far if it finds the value it replaced it with "false" so i'm half way there..
VBA Code:
       Sub Macro3()
'
' Macro3 Macro
'
Dim sh1 As Worksheet, sh2 As Worksheet
Dim f As Range
Dim i As Long, col1 As Long, col2 As Long, ini As Long
 
'set worksheet
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Brands")
 
' Pull Leadtime
Set a1 = sh1.Cells.Find("Brand", , xlValues, xlPart, , , False) ' Find Brand
If Not a1 Is Nothing Then
col1 = a1.Column
ini = a1.Row + 2
Set a1 = sh1.Cells.Find("Brand", , xlValues, xlPart, , , False) ' Find Brand ' is this needed since i'm not offsetting to another column?
If Not a1 Is Nothing Then
col2 = a1.Column
For a2 = ini To sh1.Cells(Rows.Count, col1).End(3).Row
Set a1 = sh2.Cells.Find(sh1.Cells(a2, col1).Value, , xlFormulas, xlPart, xlByRows, xlNext, False)
If Not a1 Is Nothing Then
sh1.Cells(a2, col2).Value = a1.Interior.Color = 5287936 ' Highlight isn't working, and changed the found value to 'false'
End If
Next
End If
End If
End Sub
 

Attachments

  • Untitled.png
    Untitled.png
    28.5 KB · Views: 10

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top