Counting Rows Per Condition In VBA...

Roggie

New Member
Joined
Mar 7, 2018
Messages
4
Preface: I’m brand new to VBA and have no other coding experience. I started creating a macro to do some routine formatting on an excel sheet I export regularly.
I’m looking to count rows with a certain condition and then provide a message box with the count and a brief message. This is what I have so far (re-purposed a function to count hidden rows)…

Code:
Dim cRow As Range
    Dim cRg As Range
    Dim cRows As Range
    On Error Resume Next
    Set cRows = Intersect(ActiveSheet.Range("A:A").EntireRow, ActiveSheet.UsedRange)
    If cRows Is Nothing Then Exit Sub
        For Each cRow In cRows.Columns(1).Cells
            If cRow = "($H2<>""Complete""OR($G2<>Functional Validation) AND($I2=""No""))" Then
                If cRg Is Nothing Then
                    Set cRg = cRow
                Else
                    Set cRg = Union(cRg, cRow)
                End If
            End If
        Next
        If Not cRg Is Nothing Then
            MsgBox cRg.Count & " records remain open for this release"
       Else
            MsgBox "All records have completed for this release", Done
        End If
End Sub

The result is I either get the wrong message or it counts everything. Potentially barking up the complete wrong tree, so any suggestions are appreciated.

Thanks,
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
What, in words, are you actually trying to check here?
Code:
            If cRow = "($H2<>""Complete""OR($G2<>Functional Validation) AND($I2=""No""))" Then

What is 'Functional Validation'?
 
Upvote 0
Everything from this export is text. I would like to count the rows where certain columns either have or don't have particular text. Now that you mention that, I see I'm at the very least missing some "".
 
Upvote 0
To be more specific I want to count the rows that column H it does not say complete or column G does not say Functional Validation and Column I says No.
 
Upvote 0

Forum statistics

Threads
1,224,846
Messages
6,181,307
Members
453,031
Latest member
Chris_1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top