+ Reply to Thread
Results 1 to 8 of 8

Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour rows

  1. #1
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour rows

    Good afternoon

    Windows 10
    Excel 2019


    I have been trying to work this out for days now but I am stuck and banging my head against a wall.

    The existing VBA code (called as a Macro) below looks down Colum K (starting with K2) and for each unique set of entry’s in Column K it colours the background of each unique set using one of two alternating colours to aid readability.

    This works perfectly but the criteria have changed from a single column match to a match across 4 Columns downwards.

    It needs to be where (working down the work sheet),

    Column A (Fruit) + Column B (Product Type) + Column J (Units) + Column K (Orders)

    match on multiple rows then colour each matching set of row use the alternating 2 colours as shown in the code.

    My VBA knowledge is limited and I have been unable to find a way to have more than the one existing criteria.

    I attach a example worksheet (zip file) of what I am trying to achieve.

    Please Login or Register  to view this content.
    Attachment 863336
    Attached Files Attached Files
    Last edited by Belinea2010; 03-19-2024 at 07:07 PM. Reason: To add example worksheet

  2. #2
    Registered User
    Join Date
    10-16-2023
    Location
    Poland
    MS-Off Ver
    Excel 2019 32bit WIN10
    Posts
    88

    Re: Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour

    Check this:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour

    Quote Originally Posted by Tajan View Post
    Check this:
    Please Login or Register  to view this content.

    Hi

    Thank you for your suggestion.

    Excel gives a
    Run-time error '13':
    Type mismatch

    for the code line

    Please Login or Register  to view this content.

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour

    Try below code

    PHP Code: 
    Option Explicit
    Sub colour
    ()
    Dim lr&, i&, c&, rng
    Dim u 
    As Rangest1$, st2$
    lr Cells(Rows.Count"A").End(xlUp).Row
    With Range
    ("A2:K" lr)
        .
    Interior.Color RGB(255255197' set all to 1st color
        rng = .Value ' 
    copy value into array
    End With
    For 2 To UBound(rng' loop from row 2 only
        st1 = rng(i - 1, 1) & "|" & rng(i - 1, 2) & "|" & rng(i - 1, 10) & "|" & rng(i - 1, 11) ' 
    previous combi
        st2 
    rng(i1) & "|" rng(i2) & "|" rng(i10) & "|" rng(i11' current combi
        If st2 <> st1 Then c = c + 1 '
    count the different combi
        
    If c Mod 2 1 Then ' c = 1,3,5,7...
            If u Is Nothing Then ' 
    create an union of cellsA5:K5 A6:K6 + ...
                
    Set u Range(Cells(1"A"), Cells(1"K"))
            Else
                
    Set u Union(uRange(Cells(1"A"), Cells(1"K")))
            
    End If
        
    End If
    Next
    If u Is Nothing Then Exit Sub
    u
    .Interior.Color RGB(179230255' color the union
    End Sub 
    Quang PT

  5. #5
    Registered User
    Join Date
    10-16-2023
    Location
    Poland
    MS-Off Ver
    Excel 2019 32bit WIN10
    Posts
    88

    Re: Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour

    Quote Originally Posted by Belinea2010 View Post
    Run-time error '13':
    Type mismatch

    for the code line

    Please Login or Register  to view this content.
    You probably have an error code somewhere in your data. Replace this line with:
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour

    Quote Originally Posted by Tajan View Post
    You probably have an error code somewhere in your data. Replace this line with:
    Please Login or Register  to view this content.
    Thank you, works perfectly.

  8. #8
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Help with my VBA find match from 1 criteria then colour row, to 4 criteria and colour

    Thank you everyone for your kind suggestions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Change colour of row in table to match cell colour
    By tomfiddich in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-06-2023, 02:20 PM
  2. [SOLVED] Delete rows based on multiple criteria including COLOUR, or while FILTERED
    By Rabbitoh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2020, 12:24 AM
  3. [SOLVED] Help Using VBA Colour With Criteria Across Two Columns
    By avendi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-17-2015, 01:50 AM
  4. Sumb by Colour and another criteria
    By tajsohal in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-04-2015, 06:47 PM
  5. SUMIF colour criteria
    By HayleyH86 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-05-2013, 12:38 AM
  6. Replies: 3
    Last Post: 07-15-2009, 06:13 AM
  7. Set a row colour when a criteria is met
    By OldMike in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2006, 04:00 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1