VBA font red coloured entire column range if single value.

motilulla

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

I need VBA help; I have data range C2:J51 total 8 columns out of 8 if any entire column has only single value in it make font colours red.

In this given example there are 3 columns which has in the entire column single value in the column C=G, in the column E=5 and in the column H=9 so i want these columns font should be show in red rest columns in black.

For more detail the image is attached.

*ABCDEFGHIJKL
1Data1Data2Data3Data4Data5Data6Data7Data8
2G5555955
3G5555955
4G5555955
5G5555955
6GG555955
7GG555955
8G9555955
9G55G5955
10GG5G5955
11G95G5955
12G5595955
13GG595955
14G9595955
15G555G955
16GG55G955
17G955G955
18G955G955
19G55GG955
20GG5GG955
21G95GG955
22G559G955
23GG59G955
24G959G955
25G5559955
26GG559955
27G9559955
28G55G9955
29GG5G9955
30G95G9955
31G5599955
32GG599955
33G9599955
34G55559G5
35GG5559G5
36G95559G5
37G55G59G5
38GG5G59G5
39G95G59G5
40G55959G5
41GG5959G5
42GG5959G5
43G95959G5
44G555G9G5
45GG55G9G5
46G955G9G5
47G55GG9G5
48GG5GG9G5
49G95GG9G5
50G559G9G5
51GG59G9G5
52
53
54

Thank you all.

I am using Excel 2000

Regards,
Moti
 

Attachments

  • Entire Column Single Value Red Font.png
    Entire Column Single Value Red Font.png
    39.4 KB · Views: 10

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Would you care for a ConditionalFormatting solution:
MrExcel Playbook 02 2021-09.xlsm
CDEFGHIJ
1Data1Data2Data3Data4Data5Data6Data7Data8
2G5555955
3G5555955
4G5555955
5G5555955
6GG555955
7GG555955
8G9555955
9G55G5955
10GG5G5955
11G95G5955
12G5595955
13GG595955
14G9595955
15G555G955
16GG55G955
17G955G955
18G955G955
19G55GG955
20GG5GG955
21G95GG955
22G559G955
23GG59G955
24G959G955
25G5559955
26GG559955
27G9559955
28G55G9955
29GG5G9955
30G95G9955
31G5599955
32GG599955
33G9599955
34G55559G5
35GG5559G5
36G95559G5
37G55G59G5
38GG5G59G5
39G95G59G5
40G55959G5
41GG5959G5
42GG5959G5
43G95959G5
44G555G9G5
45GG55G9G5
46G955G9G5
47G55GG9G5
48GG5GG9G5
49G95GG9G5
50G559G9G5
51GG59G9G5
motilulla
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:J51Expression=COUNTA(C$2:C$51)=COUNTIF(C$2:C$51,C$2)textNO
 
Upvote 0
Would you care for a ConditionalFormatting solution:
MrExcel Playbook 02 2021-09.xlsm
CDEFGHIJ
1Data1Data2Data3Data4Data5Data6Data7Data8
2G5555955
3G5555955
4G5555955
5G5555955
6GG555955
7GG555955
8G9555955
9G55G5955
10GG5G5955
11G95G5955
12G5595955
13GG595955
14G9595955
15G555G955
16GG55G955
17G955G955
18G955G955
19G55GG955
20GG5GG955
21G95GG955
22G559G955
23GG59G955
24G959G955
25G5559955
26GG559955
27G9559955
28G55G9955
29GG5G9955
30G95G9955
31G5599955
32GG599955
33G9599955
34G55559G5
35GG5559G5
36G95559G5
37G55G59G5
38GG5G59G5
39G95G59G5
40G55959G5
41GG5959G5
42GG5959G5
43G95959G5
44G555G9G5
45GG55G9G5
46G955G9G5
47G55GG9G5
48GG5GG9G5
49G95GG9G5
50G559G9G5
51GG59G9G5
motilulla
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:J51Expression=COUNTA(C$2:C$51)=COUNTIF(C$2:C$51,C$2)textNO
bobsan42, yes CF solution: worked perfect, after Appling CF also noticed in my example image there is a mistake column J=5 as it has single value in it has to font red.

I appreciate your help but some how I need VBA please if you can.

Good Luck

Kind Regards,
Moti
 
Upvote 0
try this code:
VBA Code:
Option Explicit

Sub motilulla_RedColumns()
    Dim rng As Range
    Set rng = ActiveSheet.Range("C2:J51")
    Dim cc As Range, i As Long
    
    For i = 1 To rng.Columns.Count
        Set cc = rng.Columns(i)
        With Application.WorksheetFunction
            If .CountA(cc) = .CountIf(cc, cc.Cells(1, 1).Value) Then
                cc.Font.Color = vbRed
            Else
                cc.Font.Color = 0
            End If
        End With
    Next i

    Set rng = Nothing
    Set cc = Nothing
End Sub
 
Upvote 0
Solution
try this code:
VBA Code:
Option Explicit

Sub motilulla_RedColumns()
    Dim rng As Range
    Set rng = ActiveSheet.Range("C2:J51")
    Dim cc As Range, i As Long
   
    For i = 1 To rng.Columns.Count
        Set cc = rng.Columns(i)
        With Application.WorksheetFunction
            If .CountA(cc) = .CountIf(cc, cc.Cells(1, 1).Value) Then
                cc.Font.Color = vbRed
            Else
                cc.Font.Color = 0
            End If
        End With
    Next i

    Set rng = Nothing
    Set cc = Nothing
End Sub
bobsan42, your macro worked like charm. ?

Thank you so much for your help and time you took for making and giving a macro solution.

Good Luck, have a great time

Kind Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
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