Results 1 to 10 of 10

Thread: Conditional formatting

  1. #1
    Senior Member
    Join Date
    Mar 2013
    Posts
    146
    Rep Power
    0

    Conditional formatting

    I need your help in this work, and hope you have a solution by the formula
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Mar 2013
    Posts
    146
    Rep Power
    0
    I think this is the solution
    =or(countif(list1;a1)>0;countif(list2;a1)>1;counti f(list3;a1)>1;countif(list4;a1)>1;countif(list5;a1 )>1)
    and other formatt
    =or(countif(list1;a1)>1;countif(list2;a1)>0;counti f(list3;a1)>0;countif(list4;a1)>0;countif(list5;a1 )>0)

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Can you please explain the logic first. I see a few cells colored when they break the numbering sequence. But I also see some inconsistencies in the ordering of the green cells also. Can you please clarify that?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  4. #4
    Senior Member
    Join Date
    Mar 2013
    Posts
    146
    Rep Power
    0
    This table I think more clarification
    Attached Files Attached Files

  5. #5
    Senior Member LalitPandey87's Avatar
    Join Date
    Sep 2011
    Posts
    222
    Rep Power
    14
    Not clearly mentioned in the file only found some colored cells and don't understand by which criteria.

  6. #6
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    Try this macro.

    Code:
    Option Explicit
    
    Sub kTest()
        
        Dim d, r As Long, c As Long, n As Long, Rng As Range
        Dim dic As Object, a() As String, x, y, Colors, j As Long
        
        Set Rng = Range("a1:j12")                   '<<< adjust the range
        d = Rng.Value2
        
        Colors = Array(255, 65535, 52479, 8388736)  '<<< add as many as interior colors
        
        Set dic = CreateObject("scripting.dictionary")
            dic.comparemode = 1
        x = Application.Index(d, 0, 1)
        n = -1
        For r = 1 To UBound(d, 1)
            For c = 3 To UBound(d, 2) Step 2
                If Len(d(r, c)) Then
                    y = Application.Match(d(r, c), x, 0)
                    If IsError(y) Then
                        If Not dic.exists(d(r, c)) Then
                            n = n + 1: dic.Item(d(r, c)) = Colors(n)
                            j = j + 1: ReDim Preserve a(1 To j)
                            a(j) = Rng.Cells(r, c + 1).Address & "|" & Colors(n)
                        Else
                            j = j + 1: ReDim Preserve a(1 To j)
                            a(j) = Rng.Cells(r, c + 1).Address & "|" & dic.Item(d(r, c))
                        End If
                    End If
                End If
            Next
        Next
        
        x = Array(dic.keys, dic.items)
        
        With Rng
            For r = 0 To UBound(x(0))
                Application.ReplaceFormat.Interior.Color = x(1)(r)
                .Replace What:=x(0)(r), Replacement:=x(0)(r), LookAt:=xlWhole, ReplaceFormat:=True
            Next
            For r = 1 To j
                y = Split(a(r), "|")
                .Range(y(0)).Interior.Color = y(1)
            Next
        End With
    
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  7. #7
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by Admin View Post
    Dim d, r As Long, c As Long, n As Long, Rng As Range
    Dim dic As Object, a() As String, x, y, Colors, j As Long
    [/code]
    Admin... I think you forgot for the moment you were writing VBA code... the d, x, y and Colors variable will all be declared as Variants for the above Dim statements. For those reading this message... in VBA, each variable must be individually declared as to its data type, otherwise it will be declared as a Variant. So, Admin meant to write the above like this...
    Code:
    Dim d As Long, r As Long, c As Long, n As Long, Rng As Range
    Dim dic As Object, a() As String, x As Long, y As Long, Colors As Long, j As Long

  8. #8
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Rick, I wouldn't be sure , except for j maybe

    Code:
    Set Rng = Range("a1:j12")                   '<<< adjust the range
        d = Rng.Value2
    Colors = Array(255, 65535, 52479, 8388736)
    x = Application.Index(d, 0, 1)
    x = Array(dic.keys, dic.items)
    y = Split(a(r), "|")
    
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  9. #9
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Quote Originally Posted by Rick Rothstein View Post
    Admin... I think you forgot for the moment you were writing VBA code... the d, x, y and Colors variable will all be declared as Variants for the above Dim statements. For those reading this message... in VBA, each variable must be individually declared as to its data type, otherwise it will be declared as a Variant. So, Admin meant to write the above like this...
    Code:
    Dim d As Long, r As Long, c As Long, n As Long, Rng As Range
    Dim dic As Object, a() As String, x As Long, y As Long, Colors As Long, j As Long
    That's all (d, x, y and Colors ) meant to be as Variant.

    and j is declared as long
    Last edited by Admin; 05-30-2013 at 01:55 PM.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  10. #10
    Senior Member
    Join Date
    Mar 2013
    Posts
    146
    Rep Power
    0
    wonderful but you can do it by formula

Similar Threads

  1. Get Displayed Cell Color (whether from Conditional Formatting or not)
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 14
    Last Post: 10-21-2013, 07:11 PM
  2. Conditional Formatting using formula.
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 02-18-2013, 11:33 PM
  3. Conditional Formatting - If/And Formula
    By Katrina in forum Excel Help
    Replies: 4
    Last Post: 11-23-2012, 12:45 AM
  4. Replies: 2
    Last Post: 09-16-2012, 02:28 AM
  5. Replies: 4
    Last Post: 07-17-2012, 12:49 AM

Posting Permissions

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