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. #14
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    623
    Location
    .
    This code works here :

    Option Explicit
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Column <> 1 Then Exit Sub
        Application.EnableEvents = False
        Call Test2(Target)
        
        Application.EnableEvents = True
    End Sub
     
     
    Sub Test2(Target As Range)
        Dim R As Range, arr, a
        Dim cel As Variant
         
        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
        
        Set R = Nothing
        
        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
        'Range("Q:U").Interior.ColorIndex = xlNone
        arr = Split(Target, "-")
        For Each a In arr
            Call DoFind(R, a)
        Next
       
    End Sub
    
    
    Sub DoFind(R, v)
    Dim c, firstAddress
    Dim Target As Range
    
    
        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
                       
                    If c.Interior.ColorIndex = 6 Then
                        If c.Offset(0, 9).Interior.ColorIndex = xlNone Then
                            c.Offset(0, 9).Interior.ColorIndex = 6
                        End If
                    End If
                    
                    Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> firstAddress
            End If
        End With
        
    End Sub

    Keep in mind, in my version of the workbook, both tables H:L & Q:U start on the same row ( #5 ) and end on the same row ( #27 ). With the code seen above, the tables will need to remain in those locations OR
    the code will need to be changed.
    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
  •