Results 1 to 18 of 18

Thread: NEED HELP MODIFYING EXISTING EVENT CODE BY ADDING ANOTHER CODE RUN AS ONE CODE.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    623
    Location
    .
    Does this work for you ?

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Column <> 1 Then Exit Sub
        Application.EnableEvents = False
        Call Test2(Target)
        Call Test3(Target)
        Application.EnableEvents = True
    End Sub
     
     
    Sub Test2(Target As Range)
        Dim r As Range, arr, a
         
         
        Set r = Range("H:L").SpecialCells(2)
        For Each cel In r
            If cel.Interior.ColorIndex = 6 Then
                cel.Interior.ColorIndex = xlNone
            End If
        Next
        arr = Split(Target, "-")
        For Each a In arr
            Call DoFind(r, a)
        Next
         
         
    End Sub
     
     
    Sub DoFind(r, v)
        With r
            Set c = .Find(v, Lookat:=xlWhole)
            If Not c Is Nothing Then
                firstAddress = c.Address
                Do
                    If c.Interior.ColorIndex = xlNone Then c.Interior.ColorIndex = 6
                    Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> firstAddress
            End If
        End With
    End Sub
    
    
    Sub Test3(Target As Range)
        Dim r As Range, arr, a
         
         
        Set r = Range("Q:U").SpecialCells(2)
        For Each cel In r
            If cel.Interior.ColorIndex = 6 Then
                cel.Interior.ColorIndex = xlNone
            End If
        Next
        arr = Split(Target, "-")
        For Each a In arr
            Call DoFind(r, a)
        Next
    End Sub
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •