Sidharth Sarkar
New Member
I am trying to convert the below sub to function but i am not getting the correct result on function.
the SUB works fine and returns correct value but function somewhere its lacking at the if condition, can someone help
>>> use code - tags <<<
the SUB works fine and returns correct value but function somewhere its lacking at the if condition, can someone help
>>> use code - tags <<<
Code:
Sub DisplayColorCount()
Dim Rng As Range
Dim CountRange As Range
Dim ColorRange As Range
Dim xBackColor As Long
On Error Resume Next
xTitleId = "dptutorials"
Set CountRange = Application.Selection
Set CountRange = Application.InputBox("Count Range :", xTitleId, CountRange.Address, Type:=8)
Set ColorRange = Application.InputBox("Color Range(single cell):", xTitleId, Type:=8)
Set ColorRange = ColorRange.Range("A1")
xReturn = 0
For Each Rng In CountRange
qqq = Rng.Value
xxx = Rng.DisplayFormat.Interior.Color
If Rng.DisplayFormat.Interior.Color = ColorRange.DisplayFormat.Interior.Color Then
xBackColor = xBackColor + 1
End If
Next
MsgBox "Count of Colors is " & xBackColor
End Sub
----------------------------------------------------------------------------------------------------------------------------
Function DisplayColorCount(Color_Rng As Range, Count_Rng As Range) As Long
Dim Rng As Range
Dim CountRange As Range
Dim ColorRange As Range
Dim xBackColor As Long
On Error Resume Next
Set CountRange = Color_Rng
Set ColorRange = Count_Rng
For Each Rng In CountRange
If Rng.DisplayFormat.Interior.Color = ColorRange.DisplayFormat.Interior.Color Then
xBackColor = xBackColor + 1
End If
Next
DisplayColorCount = xBackColor
End Function
Last edited by a moderator: