I have a Subroutine that works just fine, but I have had a request to make it a UDF
I thought it would be easy there are just two variables one is a range and the other a single cell, but the range doesn't appear to translate as expected - debugging produces an "Application-defined or Object-defined error<application-defined error="" Object-defined="" or="">"
in the sub a popup box requested the range and then another to request the cell which I have now commented out and replaced with input variables.
If anyone can shed some light on my ignorance here that would be great.<application-defined error="" Object-defined="" or="">
Dropbox - 4885953.xlsm
This is my translated code with the error line highlighted
</application-defined></application-defined>
I thought it would be easy there are just two variables one is a range and the other a single cell, but the range doesn't appear to translate as expected - debugging produces an "Application-defined or Object-defined error<application-defined error="" Object-defined="" or="">"
in the sub a popup box requested the range and then another to request the cell which I have now commented out and replaced with input variables.
If anyone can shed some light on my ignorance here that would be great.<application-defined error="" Object-defined="" or="">
Dropbox - 4885953.xlsm
This is my translated code with the error line highlighted
Rich (BB code):
Function COLOURCOUNT(CountRange As Range, ColorRange As Range)
'Count the number of cells with a specific background
'Select range to count
'Select cell to check colour against
Dim rng As Range
'Dim CountRange As Range - this line used to be in the sub
'Dim ColorRange As Range - this line used to be in the sub
Dim xBackColor As Long
Dim xFontColor As Long
On Error Resume Next
xTitleId = "ColourCount"
'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 "Number of Coloured cells is " & xBackColor & Chr(10)
End Function
Last edited: