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)…
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,
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,