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


[TABLE="class: grid, width: 300"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]000006-X[/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]000005-X[/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]000004-X[/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD][/TD]
[TD]Z[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]000003-X[/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]000002-X[/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]000001-X[/TD]
[TD]X[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

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