1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Sub cFormat()
' This is a macro for creating more than 3 conditional formats
' Install this macro (just copy paste this code in to your workbook in a new module
' Define 3 named ranges:
' data2use: with the data you want to format with more than 3 conditional formats
' conditions2use: same shape and size as data2use with format conditions for each cell in the data2use, from 1 to n
' formats2use: this range has n cells each with one format to be used when formatting data2use range
'when done, hit ALT+F8 and run the cFormat() macro
Dim conditions()
ReDim conditions(1 To Range("conditions2use").Count)
Dim i
i = 1
For Each cell In Range("conditions2use")
conditions(i) = CInt(cell.Value)
i = i + 1
Next cell
i = 1
For Each cell In Range("data2use")
Range("formats2use").Cells(conditions(i)).Select
Selection.Copy
cell.Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
i = i + 1
Next cell
End Sub |
Partager