Help using CountA or ??

Cowichandave

New Member
Joined
Jan 18, 2009
Messages
44
Office Version
  1. 2016
Each number in Column A is a person in Col B. I need a count for total entries in Col D to G for each person. Would CountA work. I am lost on this one. Any help would be appreciated.



A​
B​
C​
D​
E​
F​
G​
1
BobT
149N01
2BAS16
3DRR03
150.00​
4ATB19
339.99​
5AUM02
6BAY05
7BUI05
199.99​
8CAC03
399.94​
639.90​
2339.96​
9CAS21
10COM45
140.00​
11CONT07
298.93​
119.77​
2
3
3
1
2
BonR
115520
2CRE06
439.00​
3CAP21
195.00​
4CARL07
215.47​
5CHE11
100.00​
2
0
1
1
3
ChrisB
1CHI18
114.50​
24TH01
2066.89​
1129.94​
149.70​
3AND12
415520
86.20​
819.20​
5ATC21
6CAN91
1095.00​
7CAO01
259.56​
1691.00​
8CAR32
1316.93​
9CSC07
490.00​
490.00​
10COM44
909.20​
573.54​
975.30​
11DOW04
568.97​
12ENB03
13FAL04
14INF33
303.24​
15MAS13
515.52​
1740.35​
711.64​
769.28​
6
4
7
4
 
See if this works for you.

VBA Code:
Sub SectionCount()

    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, "C").End(xlUp).Row + 2 ' Section includes 2 empty rows
        Set rngFull = .Range("A1:G" & 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("D" & i + 1 & ":G" & i + 1).Formula = _
                        "=COUNT(" & .Range("D" & empRowFirst & ":D" & empRowLast).Address(1, 0) & ")"
                End If
            End If
        Next i
    End With

End Sub
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
See if this works for you.

VBA Code:
Sub SectionCount()

    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, "C").End(xlUp).Row + 2 ' Section includes 2 empty rows
        Set rngFull = .Range("A1:G" & 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("D" & i + 1 & ":G" & i + 1).Formula = _
                        "=COUNT(" & .Range("D" & empRowFirst & ":D" & empRowLast).Address(1, 0) & ")"
                End If
            End If
        Next i
    End With

End Sub
Works perfect. Thank you. Is there anyway to make the answers in bold and center and red
 
Upvote 0
Works perfect. Thank you. Is there anyway to make the answers in bold and center and red
Sure. Additional code in blue.

Rich (BB code):
Sub SectionCount_v02()

    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, "C").End(xlUp).Row + 2 ' Section includes 2 empty rows
        Set rngFull = .Range("A1:G" & 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("D" & i + 1 & ":G" & i + 1).Formula = _
                        "=COUNT(" & .Range("D" & empRowFirst & ":D" & empRowLast).Address(1, 0) & ")"
                        
                    ' Format
                    With .Range("D" & i + 1 & ":G" & i + 1)
                        .HorizontalAlignment = xlCenter
                        .Font.Color = -16776961
                        .Font.Bold = True
                    End With
                End If
            End If
        Next i
    End With

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,095
Messages
6,123,072
Members
449,093
Latest member
ripvw

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