Automate Adding rows & generating an ID name

mfitz51

New Member
Joined
Jun 6, 2024
Messages
5
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I need to generate secondary ID numbers (clone ID's) from an initial ID (parent ID). For example, parent ID is ID001. It has 3 clones, which need to be named ID001A, ID001B, ID001C.

My first sheet just has parental ID (1st ID) in column A and number of clones in column B (see image) Some parents have zero clones and should be skipped.

In a new sheet (could also be same sheet if that's easier) I need the parental ID (Column A), new clone ID (Column B). With each clone ID, it will need its own row. I need a code that can generate both the new clone ID (Parent ID + letter in order, (A, B, C, etc.)) and put them in a new row.

If a parent ID has zero clones, it should be skipped over and not included in the new sheet.

I've made a demo of what I'm looking for in the second image. The color coding is not necessary, I just added it to show the parental IDs.
Thank you! This would save me so much time as I am doing this manually right now for hundreds of IDs. If there's anything else I can clarify, please ask!
 

Attachments

  • Screenshot 2024-06-06 112358.png
    Screenshot 2024-06-06 112358.png
    4.3 KB · Views: 9
  • Screenshot 2024-06-06 113053.png
    Screenshot 2024-06-06 113053.png
    5.8 KB · Views: 4

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Welcome to the forum. This should do what you're after:
VBA Code:
Private Sub CloneIDs()
Dim lRowA As Long, lRowB As Long, i As Long, j As Long
Dim wsA As Worksheet, wsB As Worksheet
Set wsA = Sheets("Sheet4") '----Rename your worksheets here
Set wsB = Sheets("Sheet5") '----Rename your worksheets here
lRowA = wsA.Range("A" & Rows.Count).End(xlUp).Row
lRowB = wsB.Range("B" & Rows.Count).End(xlUp).Row + 1
For i = 2 To lRowA
    If Range("B" & i).Value > 0 Then
        For j = 1 To wsA.Range("B" & i).Value
            With wsB
                .Range("A" & lRowB).Value = wsA.Range("A" & i).Value
                .Range("B" & lRowB).Value = wsA.Range("A" & i).Value & Chr(64 + j)
            End With
            lRowB = lRowB + 1
        Next j
    End If
Next i
End Sub

Make sure to rename the sheets.

What happens if an ID has more than 26 clones? How does the suffix change?
 
Upvote 1
Solution
Thank you, that worked perfectly! If they went past the standard alphabet, it would repeat similarly to how excel repeats. (Ex: AA, AB, AC, AD, etc.) More commonly, there is also an instance when these are cloned again and get a numerical added. So, the parent in that case might be ID001A and the next clone would be ID001A1, ID001A2, etc.
 
Upvote 0
Thank you, that worked perfectly! If they went past the standard alphabet, it would repeat similarly to how excel repeats. (Ex: AA, AB, AC, AD, etc.) More commonly, there is also an instance when these are cloned again and get a numerical added. So, the parent in that case might be ID001A and the next clone would be ID001A1, ID001A2, etc.
Would you like me to adjust the code to account for those instances?
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,173
Members
452,615
Latest member
bogeys2birdies

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