Newly created Get Function is not working when I copied the syntax from a working function

C

CJ

In my spreadsheet, I have a module where the following working
functions previously existed:

Function GetPass(TR As Range) As Integer
Dim i As Integer, c As Integer
For i = 1 To TR.Count
If Trim(LCase(TR.Cells(i, 1))) = "pass" Then
c = c + 1
End If
Next i
GetPass = c
End Function
-----------------------------------------------
Function GetFail(TR As Range) As Integer
Dim i As Integer, c As Integer
For i = 1 To TR.Count
If Trim(LCase(TR.Cells(i, 1))) = "Fail" Then
c = c + 1
End If
Next i
GetFail = c
End Function
-----------------------------------------------
Function GetToDo(TR As Range) As Integer
Dim i As Integer, c As Integer, d As String
For i = 1 To TR.Count
If Trim(LCase(TR.Cells(i, 1))) = "to do" Then
c = c + 1
End If
Next i
GetToDo = c
End Function
-----------------------------------------------
Function GetTotal(TR As Range) As Integer
GetTotal = TR.Count
End Function

**********
I needed to further define a "fail" status so I renamed fail to bug in
the above function. Then I copied that function and defined it for
each of my other fail types. (Blocked, Warning, Design) - see below:

Function GetBlocked(TR As Range) As Integer
Dim i As Integer, c As Integer, d As String
For i = 1 To TR.Count
If Trim(LCase(TR.Cells(i, 1))) = "Blocked" Then
c = c + 1
End If
Next i
GetBlocked = c
End Function
-----------------------------------------------
Function GetWarning(TR As Range) As Integer
Dim i As Integer, c As Integer, d As String
For i = 1 To TR.Count
If Trim(LCase(TR.Cells(i, 1))) = "Warning" Then
c = c + 1
End If
Next i
GetWarning = c
End Function
-----------------------------------------------
Function GetDesign(TR As Range) As Integer
Dim i As Integer, c As Integer
For i = 1 To TR.Count
If Trim(LCase(TR.Cells(i, 1))) = "Design" Then
c = c + 1
End If
Next i
GetDesign = c
End Function
*******************

In my spreadsheet I have a variable called OTStatus that defines a
range of cells. Then at the top of my spreadsheet I have a call that
tallies the occurence of each of the statuses (Pass, Bug, To Do,
Design, Blocked, etc). This formula is GetPass(OTStatus).
The issue that I'm having is that the functions I copied and modified
are not working in my spreadsheet. For instance in my range (OTStatus)
I have one occurence of Bug, however the cell that is defined with
formula: GetBug(OTStatus), it shows a count of 0. Copying the code for
the function does not appear to be working.

I would be ever so grateful if someone could help. I'd gladly send you
my spreadsheet to help show you what I'm trying to explain! :)

Thank you so kindly in advance!!
 
G

Greg Wilson

None of the functions should work except the "to do" and "pass" versions
because of this example line:
If Trim(LCase(TR.Cells(i, 1))) = "Fail" Then

You are coercing the contents of TR.Cells(i, 1) to ALL lower case and then
compare it to a word that has an upper case ("F" in this case). Change your
comparison expressions to all lower case ("fail", "warning", "design" etc.)

Regards,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top