See attached sample data. Simply want to highlight numbers in COLUMN B that do not show up in COLUMN A. Would prefer VBA over conditional formatting.
Thanks
Samle Data.xlsx
See attached sample data. Simply want to highlight numbers in COLUMN B that do not show up in COLUMN A. Would prefer VBA over conditional formatting.
Thanks
Samle Data.xlsx
Sub Main() Dim hc&, c As Range, r As Range Set r = Range("B1", Cells(Rows.Count, "B").End(xlUp)) hc = xlNone 'interior Fill color r.Interior.ColorIndex = hc Set r = Range("A1", Cells(Rows.Count, "A").End(xlUp)) hc = vbRed 'interior fill color For Each c In Range("B1", Cells(Rows.Count, "B").End(xlUp)) If WorksheetFunction.CountIf(r, c) = 0 Then _ c.Interior.Color = hc Next c End Sub
Probably the simplest way
Option Explicit 'Simply want to highlight numbers in COLUMN B that do not show up in COLUMN A. Would prefer VBA over conditional formatting. Sub Demo() Dim rLookHere As Range, rCheck As Range, rCell As Range Dim i As Long Application.ScreenUpdating = False With ActiveSheet Set rLookHere = Range(.Cells(1, 1), .Cells(1, 1).End(xlDown)) Set rCheck = Range(.Cells(1, 2), .Cells(1, 2).End(xlDown)) End With For Each rCell In rCheck.Cells i = -1 On Error Resume Next i = Application.WorksheetFunction.Match(rCell.Value, rLookHere, 0) On Error GoTo 0 If i = -1 Then rCell.Interior.Color = vbRed Next Application.ScreenUpdating = True End Sub
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
Thanks guys!