rishidoshi
New Member
- Joined
- May 4, 2009
- Messages
- 20
Hi,
I am using CFColorindex function to find out the current colorindex of a cell based on the condition format state.
It works perfectly in office 2003 but not in office 2007/10. Download The excel file
The line: Select Case oFC.Operator returns an error: Runtime 1004: Application defined or object defined error.
Also, the variable in the line: CFColorindex = (rng.Value < CSng(oFC.Formula1) Or _
rng.Value > CSng(oFC.Formula2))
Or is there a new version of this function available to get the colorindex of a CF'ed cell?
(I did google a lot but couldnt find a solution)
Thanks...
Rishi
I am using CFColorindex function to find out the current colorindex of a cell based on the condition format state.
It works perfectly in office 2003 but not in office 2007/10. Download The excel file
The line: Select Case oFC.Operator returns an error: Runtime 1004: Application defined or object defined error.
Also, the variable in the line: CFColorindex = (rng.Value < CSng(oFC.Formula1) Or _
rng.Value > CSng(oFC.Formula2))
variable: oFC.Formula2 shows "Application defined or object defined error." When i take the mouse over it.
Please help me sort this out.
Or is there a new version of this function available to get the colorindex of a CF'ed cell?
(I did google a lot but couldnt find a solution)
Thanks...
Rishi
Code:
Public Function CFColorindex(rng As Range)
'---------------------------------------------------------------------
Dim oFC As FormatCondition
Dim sF1 As String
Dim iRow As Long
Dim iColumn As Long
Set rng = rng(1, 1)
If rng.FormatConditions.Count > 0 Then
For Each oFC In rng.FormatConditions
If oFC.Type = xlCellValue Then
[COLOR=#ff0000][B]Select Case oFC.Operator[/B][/COLOR]
Case xlEqual
CFColorindex = rng.Value = oFC.Formula1
Case xlNotEqual
CFColorindex = rng.Value <> CSng(oFC.Formula1)
Case xlGreater
CFColorindex = rng.Value > CSng(oFC.Formula1)
Case xlGreaterEqual
CFColorindex = rng.Value >= CSng(oFC.Formula1)
Case xlLess
CFColorindex = rng.Value < CSng(oFC.Formula1)
Case xlLessEqual
CFColorindex = rng.Value <= CSng(oFC.Formula1)
Case xlBetween
CFColorindex = (rng.Value >= CSng(oFC.Formula1) And _
rng.Value <= CSng(oFC.Formula2))
Case xlNotBetween
CFColorindex = (rng.Value < CSng(oFC.Formula1) Or _
rng.Value > CSng([COLOR=#ff0000][B]oFC.Formula2[/B][/COLOR]))
End Select
Else
're-adjust the formula back to the formula that applies
'to the cell as relative formulae adjust to the activecell
With Application
iRow = rng.Row
iColumn = rng.Column
sF1 = .Substitute(oFC.Formula1, "ROW()", iRow)
sF1 = .Substitute(sF1, "COLUMN()", iColumn)
sF1 = .ConvertFormula(sF1, xlA1, xlR1C1)
sF1 = .ConvertFormula(sF1, xlR1C1, xlA1, , rng)
End With
CFColorindex = rng.Parent.Evaluate(sF1)
If rng.Value = "" Then CFColorindex = False
End If
If CFColorindex Then
If Not IsNull(oFC.Interior.ColorIndex) Then
CFColorindex = oFC.Interior.ColorIndex
If rng.Value = "" Then CFColorindex = False
Exit Function
End If
End If
Next oFC
End If 'rng.FormatConditions.Count > 0
End Function