Forum Discussion

NaurisLatvia28's avatar
NaurisLatvia28
Copper Contributor
Dec 28, 2018
Solved

Excel highlight numbers in range by input

I pretty much forgot about VBA, cause i was learning it in school. But i like to do something in Excel. Let's take a look at my tables from beginning.   This all is just for my lottery St...
  • JWR1138's avatar
    JWR1138
    Dec 28, 2018

    Sorry, I didn't realize you had this on multiple worksheets in the workbook, changed to a workbook change event. So the code goes in ThisWorkbook. Added to what you had posted and attached. 

     

     

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    Dim TicketRange As Range
    Dim DrawRange As Range
    Dim Cell As Range
    Dim CheckRange As Range

    Set TicketRange = Range("B4:F23")
    Set DrawRange = Range("H4:L23")

    For Each Cell In TicketRange

    Set CheckRange = Range("H4:L23").Find(What:=Cell.Value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)

    If Not CheckRange Is Nothing And Cell.Value <> "" Then

    Cell.Interior.ColorIndex = 4

    Else

    Cell.Interior.ColorIndex = 0

    End If

    Next Cell

    End Sub