Consulting

Results 1 to 4 of 4

Thread: Intersecting range and array

  1. #1

    Intersecting range and array

    I have a dynamic range called rngProcs. This range is 3 columns wide. Defined as =OFFSET(Mod!$B$9:$B$1000,0,0,COUNTA(Mod!$B$9:$B$1000),3). The first column as this range (B) are numbers. i.e 1,2,3,4 going down from B9.
    I also create sheets with numbers on them. Let's say 2,5,6. I want to highlight any row in this range where the sheet name matches the first column. I'm a bit stuck on how to do this. Any help would be appreciated.

    Kind regards

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    =countif(Mod!B9:B1000,A1)>0

  3. #3
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location
    Run this from the sheet which contains range "rngprocs"

    This is not dynamic, and if worksheet values will change, then need to use conditional formatting

    What code does

    For each worksheet in the workbook it compares the value of each number in columnB (converted to text) with the worksheet name and turns the backgound colour of the cell in columnB grey if they are equal. Checking starts in cell B9.

    Sub sheetnameMatch()
    Dim CellValue As String 'to hold cell value as text
    For i = 1 To Sheets.Count
        For r = 9 To 8 + Range("rngprocs").Rows.Count
            CellValue = ActiveSheet.Cells(r, 2).Value
                If CellValue = Sheets(i).Name Then
                    ActiveSheet.Cells(r, 2).Interior.ColorIndex = 15
                End If
        Next r
    Next i
    End Sub

  4. #4
    Thank you so much that's great

Posting Permissions

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