Excel - A macro to get the equivalent numerical codes for colors

Ask a question

This macro allows you to get a color code, you can modify it to your convenience:

Sub distri_color()   
  Dim Lign As Integer  
  For Lign = 1 To 12   
    Worksheets(1).Range("C" & Lign).Value = Worksheets(1).Range("B" & Lign).Interior.Color   
  Next Lign  
End Sub
  • 'Replace 12 by the number of lines you want to process.
  • 'Replace "C" by the column you want to use for the result (color code).
  • 'Replace "B" by the column that contains the color to be filtered.

Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team