Coloring in problem.. ha!

Lukums

Board Regular
Joined
Nov 23, 2015
Messages
195
Greetings

I have a coloring in issue:

I have a sheet, and in column A there are JobIDs with same grouped number A1=1, A2=1, A3=1, A4=3 ,A5=3 ,A6=3.

I currently have this: which color codes the batches correctly.

Issue 1: It works for 56 lines and dies probably because I'm using cindex. It needs to run for as many group IDs I have in the A column.
Issue 2: It works only in row 1, I need to it work from A:Z.

Also it would be lovely to have only 2 colors instead of working down the entire color pallet

Thanks guys!

Code:
Sub dupColors()


On Error Resume Next


Dim i As Long, cIndex As Long
cIndex = 37
Cells(1, 1).Interior.ColorIndex = cIndex
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    If Cells(i, 1) = Cells(i + 1, 1) Then
        Cells(i + 1, 1).Interior.ColorIndex = cIndex
    Else
        If Cells(i + 1, 1) <> "" Then
            cIndex = cIndex + 1
            Cells(i + 1, 1).Interior.ColorIndex = cIndex
        End If
    End If
    
    
    
Next i


On Error GoTo 0


End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
It works only in row 1, I need to it work from A:Z
Row 1 ? Do you mean column A ?

Re "I need to it work from A:Z", do you mean you want to check each column in the same way as column A, or A-Z should be colored the same as column A ?
 
Last edited:
Upvote 0
So I assume you found a piece of code that you thought would do what you want but it does not.

So please tell me what your wanting.

You said you only wanted two colors what two colors

And you want this to work in Column A to Z is that correct?

So if cell value=? Do what?
 
Upvote 0
Maybe this :
Code:
Sub dupColors()
Dim i As Long, cIndex As Long
[A:Z].Interior.ColorIndex = 0
cIndex = 37
Cells(1, 1).Interior.ColorIndex = cIndex
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    If Cells(i, 1) = Cells(i + 1, 1) Then
        Cells(i + 1, 1).Resize(, 26).Interior.ColorIndex = Cells(i, 1).Interior.ColorIndex
    Else
        If Cells(i + 1, 1) <> "" Then
            If Cells(i, 1).Interior.ColorIndex = cIndex Then
                Cells(i + 1, 1).Resize(, 26).Interior.ColorIndex = cIndex + 1
            Else
                Cells(i + 1, 1).Resize(, 26).Interior.ColorIndex = cIndex
            End If
        End If
    End If
Next i
End Sub
 
Upvote 0
Maybe this :
Code:
Sub dupColors()
Dim i As Long, cIndex As Long
[A:Z].Interior.ColorIndex = 0
cIndex = 37
Cells(1, 1).Interior.ColorIndex = cIndex
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    If Cells(i, 1) = Cells(i + 1, 1) Then
        Cells(i + 1, 1).Resize(, 26).Interior.ColorIndex = Cells(i, 1).Interior.ColorIndex
    Else
        If Cells(i + 1, 1) <> "" Then
            If Cells(i, 1).Interior.ColorIndex = cIndex Then
                Cells(i + 1, 1).Resize(, 26).Interior.ColorIndex = cIndex + 1
            Else
                Cells(i + 1, 1).Resize(, 26).Interior.ColorIndex = cIndex
            End If
        End If
    End If
Next i
End Sub


You sir are a god - perfect. !!! Thank you!:)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top