+ Reply to Thread
Results 1 to 38 of 38

What is the most number of consecutive colors.

Hybrid View

  1. #1
    Registered User
    Join Date
    01-25-2013
    Location
    tr
    MS-Off Ver
    2007
    Posts
    75

    Re: What is the most number of consecutive colors.

    Dear Sixthsense,

    I did the wrong test.
    The first summer of the year, even if the macros incorrect.

    if you don;
    E: K is red all data from
    value of "0" is doing.
    Yet the value "7" will be.

    It also handles empty cells will take.
    (Empty cells will be traded.)
    (Skip empty cells)


    This macro message: 11
    Sub GetMax()
    Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long
    Dim rMyRng As Range, r As Range
    
    lEndRw = Cells(Rows.Count, "E").End(xlUp).Row
    Set rMyRng = Range("E1:K" & lEndRw)
    
    For i = 2 To lEndRw
        For Each r In rMyRng.Rows(i).Cells
            If r.Font.ColorIndex = 3 Then
                lTemp = lTemp + 1
            Else
                If lTemp > lMax Then lMax = lTemp
                lTemp = 0
            End If
        Next r
        Cells(i, "B").Value = lMax
        lMax = 0
    Next i
    
    End Sub
    Last edited by pixel34; 12-16-2013 at 04:39 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: What is the most number of consecutive colors.

    Try this...

    Sub GetMax()
    Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long
    Dim rMyRng As Range, r As Range, x As Byte, sCol As String
    
    lEndRw = Cells(Rows.Count, "E").End(xlUp).Row
    Set rMyRng = Range("E1:K" & lEndRw)
    
    For x = 1 To 2
        sCol = "A": iColor = -4105 'For Black
        If x = 2 Then sCol = "B": iColor = 3 'For Black
        
        For i = 2 To lEndRw
            For Each r In rMyRng.Rows(i).Cells
                If r.Value <> "" Then
                    If r.Font.ColorIndex = iColor Then
                        lTemp = lTemp + 1
                    Else
                        If lTemp > lMax Then lMax = lTemp
                        lTemp = 0
                    End If
                End If
            Next r
            Cells(i, sCol).Value = lMax
            lTemp = 0
            lMax = 0
        Next i
    Next x
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

+ 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] Counts two consecutive number???
    By thangkhi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-13-2013, 01:07 PM
  2. [SOLVED] Filter by Consecutive Cell Values or Colors
    By thelegazy in forum Excel General
    Replies: 10
    Last Post: 07-26-2013, 12:20 PM
  3. Count number of consecutive cells
    By skullte in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-07-2013, 03:20 AM
  4. [SOLVED] How to get the number of times exactly 4 consecutive cells have a number greater than 6?
    By llane5150 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-29-2013, 11:23 PM
  5. Difference between consecutive number
    By loudwallace in forum Excel General
    Replies: 6
    Last Post: 08-18-2010, 04:07 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