Fill define colours

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

I got results in cells C8:C70
Define colours in the cell F7:F16 as shown for different 9 patterns.


In the cell C6 got 3-X, I want to fill all 3-X find in Column C with colour is find in cell F15, and only the below the 3-X fill colours as per pattern (colours shown in cells F7:F16)

Example 3-X is in the cells C12:C13 so fill below in the 2-2 colours from as shown in F14

Example data..


Book1
ABCDEFG
1
2
3
4
5
63-XFill These
7ResultsColours
81-X0
901-1
101-11-X
112-11-2
123-X2-1
133-X2-X
142-22-2
152-X3-X
161-13-2
171-X
182-1
193-X
202-2
212-X
221-1
231-1
242-1
253-X
262-X
271-1
282-2
292-1
303-X
313-2
320
332-X
342-1
353-X
362-2
371-X
380
393-X
403-X
413-X
423-X
433-X
442-X
451-2
460
470
483-X
491-1
501-1
512-X
522-1
533-X
541-X
552-2
562-1
573-X
580
591-1
602-1
613-X
623-X
632-X
642-2
652-1
663-X
673-X
683-X
691-X
702-X
71
72
Sheet1


Thank you in advance

Regards,
Kishan
 
Last edited:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi,

I tried to get cell coloured with conditional formatting but get one colour below the
3-X

Please help with VBA


Book1
ABCDEFG
1
2
3
4
5
63-XFill These
7ResultsColours
81-X0
901-1
101-11-X
112-11-2
123-X2-1
133-X2-X
142-22-2
152-X3-X
161-13-2
171-X
182-1
193-X
202-2
212-X
221-1
231-1
242-1
253-X
262-X
271-1
282-2
292-1
303-X
313-2
320
332-X
342-1
353-X
362-2
371-X
380
393-X
403-X
413-X
423-X
433-X
442-X
451-2
460
470
483-X
491-1
501-1
512-X
522-1
533-X
541-X
552-2
562-1
573-X
580
591-1
602-1
613-X
623-X
632-X
642-2
652-1
663-X
673-X
683-X
691-X
702-X
71
72
Sheet2



Condition 1 =IF(C$6=C8,1,0)
Contition 2 =IF(C$6=C7,1,0)

Thank you in advance

Regards,
Kishan
 
Last edited:
Upvote 0
Hi,

Cannot get using conditional formatting, because my version has only 3 conditions could be applied, and I am looking for 9, please help with VBA solution

Thank you in advance

Regards,
Kishan
 
Upvote 0
Assume all cells in C8:C70 are text, including the zeros.

Use a formula to determine which cells to format

yh8MxCh.png


Four rules. Applies to: =$C$8:$C$70
=C8="0"
=LEFT(C8)="1"
=LEFT(C8)="2"
=LEFT(C8)="3"

yYZXhOZ.png
 
Upvote 0
Assume all cells in C8:C70 are text, including the zeros.

Use a formula to determine which cells to format

yh8MxCh.png


Four rules. Applies to: =$C$8:$C$70
=C8="0"
=LEFT(C8)="1"
=LEFT(C8)="2"
=LEFT(C8)="3"

yYZXhOZ.png
Hi thisoldman, thank you for the giving a conditional formatting formulas

Using as you describe it is giving a result as shown below.


Book1
ABCDEFG
1
2
3
4
5
63-XFill These
7ResultsColours
81-X0
901-1
101-11-X
112-11-2
123-X2-1
133-X2-X
142-22-2
152-X3-X
161-13-2
171-X
182-1
193-X
202-2
212-X
221-1
231-1
242-1
253-X
262-X
271-1
282-2
292-1
303-X
313-2
320
332-X
342-1
353-X
362-2
371-X
380
393-X
403-X
413-X
423-X
433-X
442-X
451-2
460
470
483-X
491-1
501-1
512-X
522-1
533-X
541-X
552-2
562-1
573-X
580
591-1
602-1
613-X
623-X
632-X
642-2
652-1
663-X
673-X
683-X
691-X
702-X
71
72
thisoldman


But I want as shown in the post#1 only 3-X in background in yellow and font in black and next to 3-X patterns as shown pre define in the cells F8:F16


Book1
ABCDEFG
1
2
3
4
5
63-XFill These
7ResultsColours
81-X0
901-1
101-11-X
112-11-2
123-X2-1
133-X2-X
142-22-2
152-X3-X
161-13-2
171-X
182-1
193-X
202-2
212-X
221-1
231-1
242-1
253-X
262-X
271-1
282-2
292-1
303-X
313-2
320
332-X
342-1
353-X
362-2
371-X
380
393-X
403-X
413-X
423-X
433-X
442-X
451-2
460
470
483-X
491-1
501-1
512-X
522-1
533-X
541-X
552-2
562-1
573-X
580
591-1
602-1
613-X
623-X
632-X
642-2
652-1
663-X
673-X
683-X
691-X
702-X
71
72
Sheet1


I am not sure but this only could be done by only VBA I think so...

Thank you in advance

Regards,
Kishan
 
Last edited:
Upvote 0
Hi,

Any ideas need help please

Thank you in advance

Regards,
Kishan
 
Upvote 0
If you run this macro, it will set the conditional formatting conditions that you want.
You only have to run it once.
Thereafter, you can copy the formatting to any new cells.
If you change any values in the Fill List, F8:F16, the CF cond
If you change a color in the Fill List, or if you add any cells to the Fill List, you should run the macro again.

Code:
Sub test()
    Dim FillList As Range, rngCF As Range
    Dim oneCell As Range, cfCell As Range
    Dim strAddress As String, strFormula As String
    
    With Sheet1
        Set FillList = .Range("F8:F16"): Rem adjust
        Set rngCF = .Range("C:C")
    End With
    rngCF.FormatConditions.Delete
    Set rngCF = rngCF.SpecialCells(xlCellTypeConstants)

    For Each cfCell In rngCF
        With cfCell
            strAddress = .Address(False, False, xlA1)
            For Each oneCell In FillList
               
                strFormula = strAddress & "&"""" = " & oneCell.Address(True, True, xlA1) & "&"""""
               ' MsgBox strFormula
                'Exit Sub
                strFormula = "=AND(LEN(" & strAddress & ")>0," & strFormula & "   )"
                'MsgBox strFormula
                'Exit Sub
                With .FormatConditions
                    .Add Type:=xlExpression, Formula1:=strFormula
                    .Item(cfCell.FormatConditions.Count).SetFirstPriority
                    With .Item(1).Interior
                        .Color = oneCell.Interior.Color
                    End With
                End With
            Next oneCell
        End With
    Next cfCell
End Sub
 
Upvote 0
If you run this macro, it will set the conditional formatting conditions that you want.
You only have to run it once.
Thereafter, you can copy the formatting to any new cells.
If you change any values in the Fill List, F8:F16, the CF cond
If you change a color in the Fill List, or if you add any cells to the Fill List, you should run the macro again.

Code:
Sub test()
    Dim FillList As Range, rngCF As Range
    Dim oneCell As Range, cfCell As Range
    Dim strAddress As String, strFormula As String
    
    With Sheet1
        Set FillList = .Range("F8:F16"): Rem adjust
        Set rngCF = .Range("C:C")
    End With
    rngCF.FormatConditions.Delete
    Set rngCF = rngCF.SpecialCells(xlCellTypeConstants)

    For Each cfCell In rngCF
        With cfCell
            strAddress = .Address(False, False, xlA1)
            For Each oneCell In FillList
               
                strFormula = strAddress & "&"""" = " & oneCell.Address(True, True, xlA1) & "&"""""
               ' MsgBox strFormula
                'Exit Sub
                strFormula = "=AND(LEN(" & strAddress & ")>0," & strFormula & "   )"
                'MsgBox strFormula
                'Exit Sub
                With .FormatConditions
                    .Add Type:=xlExpression, Formula1:=strFormula
                    .Item(cfCell.FormatConditions.Count).SetFirstPriority
                    With .Item(1).Interior
                        .Color = oneCell.Interior.Color
                    End With
                End With
            Next oneCell
        End With
    Next cfCell
End Sub
Hi mikerickson, thank you for giving a VBA solution

After I run find it stops at the line below
Code:
 .Add Type:=xlExpression, Formula1:=strFormula
And produce the following error

Error ' 5 ' occurred at run time:
Invalid argument or call to procedure

I tried to goggle but for me it is been impossible to find the solution

Please could you check?

Thank you in advance

Regards,
Kishan
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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