Cowichandave
New Member
- Joined
- Jan 18, 2009
- Messages
- 44
- Office Version
- 2016
In the result below countA is counting the entire column and showing 7 . It should only show 6 . The first number in column 5 (2701.12) is the sum and should not be counted. What am I forgetting? Sheet starts in Column C
VBA Code
RESULT
VBA Code
VBA Code:
Dim ws As Worksheet
Dim rngFull As Range
Dim arr As Variant
Dim rowLast As Long, i As Long
Dim empRowFirst As Long, empRowLast As Long
Set ws = ActiveSheet
With ws
rowLast = .Cells(Rows.count, "E").End(xlUp).Row + 2 ' Section includes 2 empty rows
Set rngFull = .Range("C1:S" & rowLast)
arr = rngFull.Value
For i = 1 To UBound(arr)
If arr(i, 3) <> "" Then
If arr(i - 1, 3) = "" Then
empRowFirst = i
ElseIf arr(i + 1, 3) = "" Or i = (UBound(arr) - 1) Then
empRowLast = i
.Range("G" & i + 1 & ":S" & i + 1).Formula = _
"=COUNT(" & .Range("G" & empRowFirst & ":G" & empRowLast).Address(1, 0) & ")"
2 | BON07 | 2701.12 | ||
1 | CRE06 | 439.00 | ||
2 | CAP21 | |||
3 | CAR21 | 215.47 | ||
4 | CHE11 | |||
5 | CYC08 | 130.00 | ||
6 | ELM01 | 416.66 | ||
7 | FOOT07 | 770.00 | ||
8 | ALL07 | |||
9 | ALL10 | |||
10 | MOR03 | |||
11 | NOR37 | |||
12 | PP07 | |||
13 | RCM180 | |||
14 | RCMPSER | 729.99 | ||
15 | ROG06 | |||
16 | UNI40 | |||
7 |
Last edited by a moderator: