Ok just as an extension ive produced some code that will work with conditional formatting as well
Code:
Sub GetColourIndex(rngTest As Range)
'obtains the displayed colorindex for a range of cells
'works with normal formating and conditional formating
'written by D Coutts on 24/02/2005
Dim cl As Range
Dim cl2 As Range
'loop through each cell and check formatting Conditional or otherwise
For Each cl In rngTest
Set cl2 = cl.Offset(0, 1)
'count the number of conditional formats on the specific cell
For i = 1 To cl.FormatConditions.Count
With cl.FormatConditions.Item(i)
'check to see if type cell value is or formula is
If .Type = 1 Then
'if cell value is then obtain the type and see if cell matches conditions
'if it does display the colorindex of that cell in next cell
Select Case .Operator
Case xlLess
If CStr(cl.Value) < .Formula1 Then _
cl2.Formula = .Interior.ColorIndex
Case xlBetween
If cl.Value >= CInt(.Formula1) And cl.Value <= CInt(.Formula2) Then _
cl2.Formula = .Interior.ColorIndex
Case xlGreater
If CStr(cl.Value) > .Formula1 Then _
cl2.Formula = .Interior.ColorIndex
Case xlNotBetween
If Not (CStr(cl.Value) >= .Formula1 And CStr(cl.Value) <= .Formula2) Then _
cl2.Formula = .Interior.ColorIndex
Case xlGreaterEqual
If CStr(cl.Value) >= .Formula1 Then _
cl2.Formula = .Interior.ColorIndex
Case xlLessEqual
If CStr(cl.Value) <= .Formula1 Then _
cl2.Formula = .Interior.ColorIndex
Case xlEqual
If CStr(cl.Value) = .Formula1 Then _
cl2.Formula = .Interior.ColorIndex
Case xlNotEqual
If Not (CStr(cl.Value) = .Formula1) Then _
cl2.Formula = .Interior.ColorIndex
End Select
'if type of conditional format is formulais then calculate the formula
'and match with the cell value
ElseIf .Type = 2 Then
cl2.Formula = .Formula1
If cl.Value = cl2.Value Then
cl2.Formula = .Interior.ColorIndex
Else
'if no match set the written cell value to be blank
cl2.Formula = ""
End If
End If
End With
Next i
'for every cell without a conditional format applied pick up the colorindex
If cl2.Formula = "" Then
cl2.Value = cl.Interior.ColorIndex
End If
Next cl
'clear object variables
Set cl = Nothing
Set cl2 = Nothing
End Sub
to use the above code write a small procedure such as this
Code:
Sub useabove()
Range("b1").EntireColumn.Insert
GetColourIndex Range("A1:A15")
End Sub
Hope this will make things a bit easier for you
All the best
Dave