D
dev-all
I have a spreadsheet that tracks "violations" by setting background colors of
cells and by placing text in certain "custom" cells. I wrote a UDF to
calculate how many violations appear in a specified range. I then call this
UDF using a formula like...
=GetViolationCount($A1:$AF1)
It works great in a worksheet. In other words, every cell in which I call
the UDF with an appropriate range, the cell shows the correct value.
In another portion of the spreadsheet, I have UserForm that searches for
any of several, user chosen, criteria. One of the choices is "has
violations". So I want to look at the cell that contains the result of my
GetViolationCount UDF and simply test if it is greater than 0. ie....
CInt(allDataRange(curRow, kViolationCountColumnIndex).Value) > 0
No matter which property I use to access that cell, I've tried Value,
Value2 and Text among others, I always get back an empty string. Other
properties like Address etc return appropriate values. Am I trying to do
something impossible or am I being stupid?
Here is the entire UDF if it matters...
Public Function GetViolationCount(inRange As Range) As Integer
Dim numViolations As Integer
numViolations = 0
Dim numRows As Integer
Dim nthRow As Integer
numRows = inRange.Rows.Count
Dim numCols As Integer
Dim nthColumn As Integer
numCols = inRange.Columns.Count
For nthRow = 1 To numRows
For nthColumn = kFirstViolationColumnIndex To numCols
Dim tStr As String
tStr = CStr(inRange(nthRow, nthColumn).Value)
If IsCustomColumn(nthColumn) Then
If inRange(nthRow, nthColumn).Value <> "" Then
numViolations = numViolations + 1
End If
Else
If inRange(nthRow, nthColumn).Interior.colorIndex <> xlNone
Then
numViolations = numViolations + 1
End If
End If
Next nthColumn
Next nthRow
GetViolationCount = numViolations
End Function
cells and by placing text in certain "custom" cells. I wrote a UDF to
calculate how many violations appear in a specified range. I then call this
UDF using a formula like...
=GetViolationCount($A1:$AF1)
It works great in a worksheet. In other words, every cell in which I call
the UDF with an appropriate range, the cell shows the correct value.
In another portion of the spreadsheet, I have UserForm that searches for
any of several, user chosen, criteria. One of the choices is "has
violations". So I want to look at the cell that contains the result of my
GetViolationCount UDF and simply test if it is greater than 0. ie....
CInt(allDataRange(curRow, kViolationCountColumnIndex).Value) > 0
No matter which property I use to access that cell, I've tried Value,
Value2 and Text among others, I always get back an empty string. Other
properties like Address etc return appropriate values. Am I trying to do
something impossible or am I being stupid?
Here is the entire UDF if it matters...
Public Function GetViolationCount(inRange As Range) As Integer
Dim numViolations As Integer
numViolations = 0
Dim numRows As Integer
Dim nthRow As Integer
numRows = inRange.Rows.Count
Dim numCols As Integer
Dim nthColumn As Integer
numCols = inRange.Columns.Count
For nthRow = 1 To numRows
For nthColumn = kFirstViolationColumnIndex To numCols
Dim tStr As String
tStr = CStr(inRange(nthRow, nthColumn).Value)
If IsCustomColumn(nthColumn) Then
If inRange(nthRow, nthColumn).Value <> "" Then
numViolations = numViolations + 1
End If
Else
If inRange(nthRow, nthColumn).Interior.colorIndex <> xlNone
Then
numViolations = numViolations + 1
End If
End If
Next nthColumn
Next nthRow
GetViolationCount = numViolations
End Function