Running into a situation that has me confused. I have a subroutine called DisplayFormatCount1() and converted it to a Function as I want to insert
=DisplayFormatCount2(M5:M9,65535) into various cells.
the value being returned is 0
Do i need to pass the worksheet to the function?
Orginal VBA Subroutine Here
Sub DisplayFormatCount1()
Dim Rng As Range
Dim CountRange As Range
Dim ColorRange As Range
Dim xBackColor As Long
Dim xFontColor As Long
On Error Resume Next
Set CountRange = Range("$M$5:$M$9")
xxx = 65535
For Each Rng In CountRange
qqq = Rng.Value
xxx = Rng.DisplayFormat.Interior.Color
If Rng.DisplayFormat.Interior.Color = 65535 Then
xBackColor = xBackColor + 1
End If
If Rng.DisplayFormat.Font.Color = ColorRange.DisplayFormat.Font.Color Then
xFontColor = xFontColor + 1
End If
Next
MsgBox "BackColor is " & xBackColor & Chr(10) & "FontColor is " & xFontColor
My attempt to create a UDF Function
Function DisplayFormatCount3(CountRange As Range, inXXX) As Long
Dim CelVal As Range
Dim ColorRange As Range
Dim xBackColor As Long
Dim xFontColor As Long
On Error Resume Next
Set CR = CountRange
For Each CelVal In CR
qqq = CelVal.Value
xxx = CelVal.DisplayFormat.Interior.Color
If CelVal.DisplayFormat.Interior.Color = inXXX Then
xBackColor = xBackColor + 1
End If
If CelVal.DisplayFormat.Font.Color = ColorRange.DisplayFormat.Font.Color Then
xFontColor = xFontColor + 1
End If
Next
MsgBox "BackColor is " & xBackColor & Chr(10) & "FontColor is " & xFontColor
End Function
=DisplayFormatCount2(M5:M9,65535) into various cells.
the value being returned is 0
Do i need to pass the worksheet to the function?
Orginal VBA Subroutine Here
Sub DisplayFormatCount1()
Dim Rng As Range
Dim CountRange As Range
Dim ColorRange As Range
Dim xBackColor As Long
Dim xFontColor As Long
On Error Resume Next
Set CountRange = Range("$M$5:$M$9")
xxx = 65535
For Each Rng In CountRange
qqq = Rng.Value
xxx = Rng.DisplayFormat.Interior.Color
If Rng.DisplayFormat.Interior.Color = 65535 Then
xBackColor = xBackColor + 1
End If
If Rng.DisplayFormat.Font.Color = ColorRange.DisplayFormat.Font.Color Then
xFontColor = xFontColor + 1
End If
Next
MsgBox "BackColor is " & xBackColor & Chr(10) & "FontColor is " & xFontColor
My attempt to create a UDF Function
Function DisplayFormatCount3(CountRange As Range, inXXX) As Long
Dim CelVal As Range
Dim ColorRange As Range
Dim xBackColor As Long
Dim xFontColor As Long
On Error Resume Next
Set CR = CountRange
For Each CelVal In CR
qqq = CelVal.Value
xxx = CelVal.DisplayFormat.Interior.Color
If CelVal.DisplayFormat.Interior.Color = inXXX Then
xBackColor = xBackColor + 1
End If
If CelVal.DisplayFormat.Font.Color = ColorRange.DisplayFormat.Font.Color Then
xFontColor = xFontColor + 1
End If
Next
MsgBox "BackColor is " & xBackColor & Chr(10) & "FontColor is " & xFontColor
End Function