Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm building a test matrix in Excel and for some reason the macro that I am writing is having a problem reading the cells in the range that I pass to the functions.
The test matrix is a workbook comprised of many sheets (about 20 + to date) and contains the results pass or fail for each test case. However instead of counting the number of times the word pass or fail appears, the macro reads each cell as blank, which is incorrect.Here is the basic code that is used in each function:
Function GetPass(TR As Range) As Integer
Dim x As Integer
'Initialization of variablesx = 0
For Each Cell In TR
If Text = "pass" Then
x = x + 1
GetPass = x
End If
Next Cell
'Loops through each cell in the range
'The If checks to see if the contents are the word "pass"
'Returns the number of times the word "pass" is found as the numeric value of the functionEnd Function

Hi,
I guess this would help you,
I’ve modified the code, check if this works or else mail me the detail requirement
so that I’ll try to help youPublic x
Function getpass(TR As Range) As Integer
Dim x As Integer
'initialization of variables
x = 0
For Each Cell In TR
If UCase(Cell.Text) = "PASS" Then
x = x + 1
getpass = x
End If
Next Cell
MsgBox x
End Function
Sub Test()
Call getpass(Selection.Cells)
End Sub

Out of interest, you don't need to use 'x'. You can use the function name as your counter, since its the returned integer anyway:
GetPass = GetPass + 1
Also, since you can evaluate a boolean as an integer (whereby 0 is false, and -1 is true), then your loop could be:
For Each xCell In TR
GetPass = GetPass - (UCase(xCell.Text) = "PASS")
Next CellJust a thought
Tom

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |