LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default UDF Question

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 Macro/VB Question DDE Question MadDog22 Excel Worksheet Functions 1 March 10th 10 01:47 AM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 02:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"