Count data upwards

bdtran

New Member
Joined
Oct 11, 2018
Messages
33
Hello All,

I am trying to get the result in column-A and I really need help with a formula to automatically count upwards as I insert data into column-B.

In the example below I just wanted to count data "X" in column-B upwards as in our situation, the data has been inserted in the top row as needed with a new row added.

Thanks much for your help.
*BDT


AB
1
2000006-XX
3Y
4000005-XX
5000004-XX
6Z
7000003-XX
8000002-XX
9000001-XX

<tbody>
</tbody>
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hello,

You could test following event macro

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$B$2" Then Exit Sub
If Target = "" Then Target.Offset(0, -1).ClearContents: Exit Sub
Dim x As Long
x = Application.WorksheetFunction.CountIf(Range("B3:B100"), Target.Value)
Target.Offset(0, -1) = Format(x + 1, "000000" & "-" & Target.Value)
End Sub

Hope this will help
 
Upvote 0
James,

Thanks much for your quick response. I realize that I also need to count upwards data "Z" and Data "Y" as well as they are inserted in the top row.

Really appreciate for your help.
Thanks,
*BDT
 
Upvote 0
Hello,

Have you already tested the macro ...???

Since it does perform what you are asking for ...

HTH
 
Upvote 0
James,

I tested it and it worked with the result I am looking for.

Is there any way that can be applied the same count for data "Z" and "Y"?

Also with your code, I have to insert the data "X" in the B2 cell in order to get the result in A2. Is there a way that I can insert data "X" in any cell within the defined range for example B1:B100? because my production data comprise 30 rows for each record in column-A. Such as in the above table "000006-X" indicates a record number comprises of 30 rows data following.

Thank you again for your help.
*BDT
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,971
Members
449,059
Latest member
oculus

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