Help - Autofill series based on specified max value

chong

New Member
Joined
Jul 17, 2011
Messages
2
Hi all, I am currently running into trouble with one of the tasks I am working on.
I need to autofill column B incrementally (by 1) with reference to the maximum value in the cell in column A.

Col A Col B
5 1
5 2
5 3
5 4
5 5
5 1
5 2
5 3
3 1
3 2
3 3
3 1
3 2
4 1
4 2
4 3
4 4
4 1
4 2
4 3

Is there a macro where I would be able to use? I have thousands of records in my listing.

Regards
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
In the example which follows, put a 1 in cell B30 then copy the formula in cell B31 down. Later you can copy and Paste-Special|Values to convert the formulae to values:
Excel Workbook
AB
3051
3152
3253
3354
3455
3551
3652
3753
3831
3932
4033
4131
4232
4341
4442
4543
4644
4741
4842
4943
May 3
 
Upvote 0
If you want a macro:

Code:
Sub Test()
    Dim LR As Long
    Dim r As Long
    Dim i As Long
    LR = Range("a" & Rows.Count).End(xlUp).Row
    i = 1
    Cells(1, 2).Value = i
    i = i + 1
    For r = 2 To LR
        If Cells(r, 1).Value = Cells(r - 1, 1).Value Then
            If i <= Cells(r, 1).Value Then
                Cells(r, 2).Value = i
                i = i + 1
            Else
                i = 1
                Cells(r, 2).Value = i
                i = i + 1
            End If
        Else
            i = 1
            Cells(r, 2).Value = i
            i = i + 1
        End If
    Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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