Font color Number

cotech_10

Board Regular
Joined
Sep 11, 2010
Messages
135
Office Version
  1. 2016
Platform
  1. Windows
I have a simple column setup in which in each individual cell will contain a paired number with a semicolon separator as per below:

202;105
120;117
4;500
39;195
32;66
41;889
8;26
212;135
108;200


What I would like to achieve is to change the font color say to the color RED of an individual number in a paired group according to a specific criteria

For example the number criteria's for font color change could be as follows: 202, 4, 889, 108 & 66

So the end result would result in the numbers 202, 4, 889, 108 and 32 colored in Red and its paired counterpart would be default black.

202;105
120;117
4;500
39;195
32;66
41;889
8;26
212;135
108;200






Thanks and Regards
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Assuming data in column A starting in row 2, see if this does what you want.

VBA Code:
Sub Colour_Font()
  Dim a As Variant, Nums As Variant
  Dim i As Long, j As Long, pos As Long
  Dim s As String
  
  Const myNums As String = "202 4 889 108 66"
  
  Nums = Split(";" & Join(Split(myNums), "; ;") & ";")
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    For i = 1 To UBound(a)
      s = ";" & a(i, 1) & ";"
      For j = 0 To UBound(Nums)
        pos = InStr(1, s, Nums(j))
        If pos > 0 Then .Cells(i, 1).Characters(pos, Len(Nums(j)) - 2).Font.Color = vbRed
      Next j
    Next i
  End With
End Sub
 
Upvote 0
Sub Colour_Font() Dim a As Variant, Nums As Variant Dim i As Long, j As Long, pos As Long Dim s As String Const myNums As String = "202 4 889 108 66" Nums = Split(";" & Join(Split(myNums), "; ;") & ";") With Range("A2", Range("A" & Rows.Count).End(xlUp)) a = .Value For i = 1 To UBound(a) s = ";" & a(i, 1) & ";" For j = 0 To UBound(Nums) pos = InStr(1, s, Nums(j)) If pos > 0 Then .Cells(i, 1).Characters(pos, Len(Nums(j)) - 2).Font.Color = vbRed Next j Next i End With End Sub
Hi Peter,

Firstly thank you for your response, greatly appreciated.

What I was looking to achieve is the string of numbers for the ciriteria can be made up of any string of numbers not a fixed number set as noted in my previous post


For example I could have the following paired numbers starting in cell A2

9;106
130;137
4;50
29;295
3;6
1;8
8;26
242;335
208;204
3;5
16;100
2;90
3;8
44;66
etc


The string of numbers could start in say cell A1 and they could be as follows:

9, 4, 8, 208, 44, 242, 6 etc

Therefore the font colored numbers would be as follows :

9;106
130;137

4;50
29;295
3;
6
1;8
8
;26
242;335
208;204
3;5
16;100
2;90
3;
8
44
;66


or the numbers could be

106, 77, 88, 109, 2, 400, 500, 199 etc


And the font colored numbers would then be :

9;106
130;137
4;50
29;295
3;6
1;8
8;26
242;335
208;204
3;5
16;100

2;90
3;8
44;66



Thanks and Regards
 
Upvote 0
The string of numbers could start in say cell A1 and they could be as follows:

9, 4, 8, 208, 44, 242, 6 etc
Would those numbers all be in cell A1 or does that represent A1, B1, C1, D1, etc... or something else.

Have you considered using XL2BB for sample data? It makes layout etc much clearer?
 
Upvote 0
Would those numbers all be in cell A1 or does that represent A1, B1, C1, D1, etc... or something else.

Have you considered using XL2BB for sample data? It makes layout etc much clearer?
Hi Peter,

Yes the first number would start in cell A1 the next number in B1, then C1, D1, etc

Thanking You
 
Upvote 0
new single number.xlsm
ABCDEFGH
1948208442426
29;106
3130;137
44;50
529;295
63;6
71;8
88;26
9242;335
10208;204
113;5
1216;100
132;90
143;8
1544;66
16
17
18
Sheet1
 
Upvote 0
Thanks for using XL2BB - makes it much easier. (y)

Try this version.

VBA Code:
Sub Colour_Font_v2()
  Dim a As Variant, Nums As Variant
  Dim i As Long, j As Long, pos As Long
  Dim s As String
  
  Nums = Split(";" & Join(Application.Index(Range("A1").Resize(, Cells(1, Columns.Count).End(xlToLeft).Column).Value, 1, 0), "; ;") & ";")
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    For i = 1 To UBound(a)
      s = ";" & a(i, 1) & ";"
      For j = 0 To UBound(Nums)
        pos = InStr(1, s, Nums(j))
        If pos > 0 Then .Cells(i, 1).Characters(pos, Len(Nums(j)) - 2).Font.Color = vbRed
      Next j
    Next i
  End With
End Sub
 
Upvote 0
Thanks for using XL2BB - makes it much easier. (y)

Try this version.

VBA Code:
Sub Colour_Font_v2()
  Dim a As Variant, Nums As Variant
  Dim i As Long, j As Long, pos As Long
  Dim s As String
 
  Nums = Split(";" & Join(Application.Index(Range("A1").Resize(, Cells(1, Columns.Count).End(xlToLeft).Column).Value, 1, 0), "; ;") & ";")
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    For i = 1 To UBound(a)
      s = ";" & a(i, 1) & ";"
      For j = 0 To UBound(Nums)
        pos = InStr(1, s, Nums(j))
        If pos > 0 Then .Cells(i, 1).Characters(pos, Len(Nums(j)) - 2).Font.Color = vbRed
      Next j
    Next i
  End With
End Sub
Hi Peter,

No problem about using XL2BB... nice little tool indeed of course and nothing like seeing the end product. makes it more clear...

I have run the script and works like a dream..!!! awesome effort.!!!

Thanking You much appreciated...
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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