ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Capturing "text" instead of the formula (https://www.excelbanter.com/excel-programming/439208-capturing-text-instead-formula.html)

Bishop

Capturing "text" instead of the formula
 
I have the following code snippet:

Pass = 0
Fail = 0
For i = 9 To (ZeroRow - 3) Step 8
If Cells(i, "H").Value = Pass Then
Pass = Pass + 1
Else
Fail = Fail + 1
End If
Next

The cells I'm referring to actually have formulas in them but when you look
at the worksheet the cells have either "Pass" or "Fail" in them. That's what
I'm trying to capture. But when I run this code it doesn't see "Pass" in any
of the cells so all of them in the for loop get assigned to Fail. I've tried
putting the word Pass in quotes:

If Cells(i, "H").Value = "Pass" Then

but that doesn't work either. How can I fix this?

Mike H

Capturing "text" instead of the formula
 
Hi,

Try this

Dim Pass As Long, i As Long
Dim Fail As Long, ZeroRow As Long
Pass = 0
Fail = 0
For i = 9 To (ZeroRow - 3) Step 8
If UCase(Cells(i, "H").Value) = "PASS" Then
Pass = Pass + 1
Else
Fail = Fail + 1
End If
Next


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Bishop" wrote:

I have the following code snippet:

Pass = 0
Fail = 0
For i = 9 To (ZeroRow - 3) Step 8
If Cells(i, "H").Value = Pass Then
Pass = Pass + 1
Else
Fail = Fail + 1
End If
Next

The cells I'm referring to actually have formulas in them but when you look
at the worksheet the cells have either "Pass" or "Fail" in them. That's what
I'm trying to capture. But when I run this code it doesn't see "Pass" in any
of the cells so all of them in the for loop get assigned to Fail. I've tried
putting the word Pass in quotes:

If Cells(i, "H").Value = "Pass" Then

but that doesn't work either. How can I fix this?



All times are GMT +1. The time now is 03:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com