Require VBA to do CF with 2 colours in the alternate rows

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,</SPAN></SPAN>

D7:Q23 for conditional format I am using the formula "=IF(D8="",0,IF(D8=0,1,0))" with one condition background red and font white I got 8000+ rows it works fine. </SPAN></SPAN>

Problem occurs when I tried to do 2 different colours for the alternate rows red & blue as shown in the second scenarios my workbook close with message not enough memory and when I force to close I see all CF is lost. But with one colour there is no problem </SPAN></SPAN>

Can it could be solved by VBA solution please</SPAN></SPAN>

Example data.... </SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRS
1
2
3
4
5n1n2n3n4n5n6n7n8n9n10n11n12n13n14
6
710001010110010
821102100201100
930003010310010
1040014020021000
1101020030032100
1212131100100001
1320040001001010
1401150100010020
1500061210120131
1601100000200240
1710210111300051
1800301020001060
1900000100012100
2010011000020011
2100002011031022
2200013002040030
2310100100050001
Sheet2


Requir like as below


Book1
ABCDEFGHIJKLMNOPQRS
1
2
3
4
5n1n2n3n4n5n6n7n8n9n10n11n12n13n14
6
710001010110010
821102100201100
930003010310010
1040014020021000
1101020030032100
1212131100100001
1320040001001010
1401150100010020
1500061210120131
1601100000200240
1710210111300051
1800301020001060
1900000100012100
2010011000020011
2100002011031022
2200013002040030
2310100100050001
Sheet3


Thank you all</SPAN></SPAN>

Excel 2000</SPAN></SPAN>
Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hello,

Does this work as expected?

Have assumed you just want to colour the cells.

Code:
Sub DOUBLE_COLOUR()
    For MY_ROWS = 7 To Range("D" & Rows.Count).End(xlUp).Row - 1
        For MY_COLS = 4 To 17
            If Cells(MY_ROWS + 1, MY_COLS).Value <= Cells(MY_ROWS, MY_COLS).Value Then
                If Round(MY_ROWS / 2, 0) <> MY_ROWS / 2 Then
                    Cells(MY_ROWS, MY_COLS).Interior.Color = vbRed
                Else
                    Cells(MY_ROWS, MY_COLS).Interior.Color = vbBlue
                End If
                    Cells(MY_ROWS, MY_COLS).Font.Color = vbWhite
            End If
        Next MY_COLS
    Next MY_ROWS
End Sub
 
Last edited:
Upvote 0
Hello,

Does this work as expected?

Have assumed you just want to colour the cells.

Code:
Sub DOUBLE_COLOUR()
    For MY_ROWS = 7 To Range("D" & Rows.Count).End(xlUp).Row - 1
        For MY_COLS = 4 To 17
            If Cells(MY_ROWS + 1, MY_COLS).Value <= Cells(MY_ROWS, MY_COLS).Value Then
                If Round(MY_ROWS / 2, 0) <> MY_ROWS / 2 Then
                    Cells(MY_ROWS, MY_COLS).Interior.Color = vbRed
                Else
                    Cells(MY_ROWS, MY_COLS).Interior.Color = vbBlue
                End If
                    Cells(MY_ROWS, MY_COLS).Font.Color = vbWhite
            End If
        Next MY_COLS
    Next MY_ROWS
End Sub
onlyadrafter, your VBA code work very perfect! I did run with real data, after the colouring both rows in the red and blue colours, workbook saved the with no problem at all.</SPAN></SPAN>

Thank you very much for the help!
</SPAN></SPAN>

Query solved!
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti :grin:
</SPAN></SPAN>
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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