Increment Duplicate value by a dash and 1

TheHack22

Board Regular
Joined
Feb 3, 2021
Messages
121
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi VBA Gurus,

I hope everyone is doing well. I have this list of Customer IDs and the number of payments for this check run.
It's company practice to increment the IDs by -1(Manually), adding one each time, while doing nothing with the first ID instance. Please see the small example below.

Is there a way to make this a repeatable process, by VBA, Power Query, or any other methods?

IDSDesired New IDs
Imr2022581Imr2022581
Imr2022581Imr2022581-1
Imr2022817Imr2022817
Imr2022817Imr2022817-1
Imr2022986Imr2022986
Imr2022986Imr2022986-1
Imr2022321Imr2022321
Imr2022321Imr2022321-1
Imr2022321Imr2022321-2
Imr2022878Imr2022878
Imr2022878Imr2022878-1
Imr2022878Imr2022878-2

Thanks
Imran
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Can be done with a simple formula.
For an ID in cell A2, here is the formula to use:
Excel Formula:
=IF(COUNTIF(A$2:A2,A2)=1,A2,A2 & "-" & COUNTIF(A$2:A2,A2)-1)
and then just copy down your column for all values.

Here is a little shorter version using the new LET function:
Excel Formula:
=LET(x,COUNTIF(A$2:A2,A2),IF(x=1,A2,A2 & "-" & x-1))
 
Upvote 0
Solution
Upvote 0
You are welcome.
Glad we were able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,216,045
Messages
6,128,484
Members
449,455
Latest member
jesski

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