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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,223,922
Messages
6,175,382
Members
452,639
Latest member
RMH2024

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