I'm quite new to VBA, so I'm guessing this is way above my head at the moment, but I've been having this procedure in mind for quite some time and the fact that I can't figure out anything that even remotely resembles a solution is killing me. So here's my problem - I would like to filter values from "Column 1" if the corresponding value in "Column 2" is "B", but only if none of the identical (duplicate) values in Column 1 have a value of "A" in "Column 2".
To simplify - the output should be "2" and "4", since those are the only values that don't have a value of "A" in "Column 2" in any of their iterations in "Column 1".
I was able to do this in Excel using two dynamic formulas and XLOOKUP, but there must be something more elegant that can be done via VBA. Right now I can only do For Each Loop that would filter all the values that have a value of "B" in Column 2 (in this case it would return all the values from "Column 1" except "3"), which isn't what I need at all.
Sub ChooseStatus()
Dim Sheet1 As Worksheet
Set Sheet1 = ThisWorkbook.Sheets("Sheet1")
'defining the area
lr = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
sr = Selection.Row
'defining categories
Item = Sheet1.Cells(sr, 1)
Status = Sheet1.Cells(sr, 2)
'loop
For i = 2 To lr
If Sheet1.Cells(i, 2) = "B" Then
Sheet1.Cells(i, 1).Interior.Color = rgbBlue
End If
Next i
End Sub
Any assistance you could provide is much appreciated.
| Item | Status |
|---|---|
| 1 | A |
| 1 | B |
| 1 | B |
| 2 | B |
| 2 | B |
| 3 | A |
| 3 | A |
| 4 | B |
| 5 | A |
| 5 | B |