create a subroutine that allows the user to select the Identifier from a drop-down menu in cell F2 and the Key from a drop-down menu in cell F3

Minmei

New Member
Joined
Jul 6, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello, I need some assistance, my code isn't working. I need to create a subroutine that allows the user to select the Identifier from a drop-down menu in cell F2 and the Key from a drop-down menu in cell F3 and any rows of the data (columns A, B, and C) whose Batch ID meets those criteria will be highlighted GREEN. Thank you so much for your assistance.
Screenshot 2023-07-06 141701.png
Sub HighlightRows()

Dim nr As Integer, I As Integer
Dim ID As String, Key As Integer
Dim ws As Worksheet
Dim rng As Range

Set ws = ThisWorkbook.Sheets("Data")
nr = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row


For I = 2 To nr
ID = ws.Cells(I, 1).Value
Key = ws.Cells(I, 3).Value (I get an error return error 6, overflow)

If ID = ws.Range("F2").Value And Key = ws.Range("F3").Value Then
Set rng = ws.Range("A" & I & ":C" & I)
rng.Interior.Color = RGB(0, 255, 0)

End If

Next I

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about using Conditional Formatting?
If so, then just select the Batch ID data cells, add to them the following CF formula and choose the highlight filling you like:
=$F$2&$F$3=LEFT($A2:$A24,2)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,933
Messages
6,181,841
Members
453,068
Latest member
DCD1872

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