Need Help with conditional counting based on cell values

hyesparky

New Member
Joined
Jan 18, 2014
Messages
3
I have a worksheet that has 18K rows. Column A is numbered and the values repeat themselves various numbers of times. I want to count the values in the adjacent column and restart the count each time the values change
so:
4 1
4 2
4 3
4 4
4 5
4 6
5 1
5 2
5 3
5 4
6 1
6 2
6
7
7
8
8

I currently only have the values in the LH column. I want a formula that will produce the numbering in the RH column.
Can anyone help me? You guys on here are all so smart and i cant figure out how to do this!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try...

B2, copied down:

=COUNTIF($A$2:A2,A2)

Note that a huge number of CountIf formulas might degrade performance.
 
Upvote 0
Hi!! Thank you! That ALMOST worked. But the renumbering starts at the last number of the like string instead of the first number of the next value

11
12
13
14
11
22
23
24
25
26
27
28
29
21
42
43
44
45
41
52
53
54

<COLGROUP><COL style="WIDTH: 48pt" span=2 width=64><TBODY>
</TBODY>
 
Upvote 0
Hi!! Thank you! That ALMOST worked. But the renumbering starts at the last number of the like string instead of the first number of the next value

11
12
13
14
11
22
23
24
25
26
27
28
29
21
42
43
44
45
41
52
53
54

<tbody>
</tbody>

The data is asumed to srart at row 2, that is, from A2 on.
 
Upvote 0
Hi,

As per Aladin's comment on the large number of Countif formulas degrading performance - if this is an issue for you, an alternative might be a VBA procedure as follows (note also assuming data begins in A2):

Code:
Sub example()


    Dim vArr        As Variant
    Dim dict        As Object
    Dim lastRow     As Long
    Dim i           As Long
    
    ' assign range to array
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    vArr = Range("A2:B" & lastRow).Value2
    
    ' initialise dictionary
    Set dict = CreateObject("scripting.dictionary")
        
    ' assign count
    With dict
        For i = 1 To UBound(vArr, 1)
            If Not .Exists(vArr(i, 1)) Then
                .Add Key:=vArr(i, 1), Item:=1
            Else
                .Item(vArr(i, 1)) = .Item(vArr(i, 1)) + 1
            End If
            vArr(i, 2) = .Item(vArr(i, 1))
        Next i
    End With
    
    ' print output array
    Range("A2").Resize(UBound(vArr, 1), 2) = vArr
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,102
Messages
6,128,851
Members
449,471
Latest member
lachbee

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