Computing.Net > Forums > Programming > Macro Problems in Excel

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Macro Problems in Excel

Reply to Message Icon

Name: Retha Williams
Date: October 28, 2002 at 11:32:16 Pacific
OS: Win 2000
CPU/Ram: 256K
Comment:

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 variables

x = 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 function

End Function



Sponsored Link
Ads by Google

Response Number 1
Name: Suresh V
Date: October 29, 2002 at 23:07:34 Pacific
Reply:

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 you

Public 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


0

Response Number 2
Name: A Certain TH
Date: October 31, 2002 at 02:25:31 Pacific
Reply:

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 Cell

Just a thought

Tom


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Macro Problems in Excel

Excel macro problem: Cell ranges www.computing.net/answers/programming/excel-macro-problem-cell-ranges/2800.html

concatenating in excel www.computing.net/answers/programming/concatenating-in-excel/14820.html

Using a macro in excel to copy data www.computing.net/answers/programming/using-a-macro-in-excel-to-copy-data/7953.html