Duplicate rows based on call value and and extra column

arendberg

New Member
Joined
Jan 23, 2024
Messages
9
Office Version
  1. 2021
Platform
  1. MacOS
Hey Guys,

Would love some help with the below sheets. I want to duplicate the rows in the Input sheet based on the number of adults and childeren, columns C and D. For every duplicated row there needs to be an extra column showing "Adult" for every adult and "Child" for every child.

Input example
Example.xlsx
ABCDEFGH
1arrivaldeparturechildrenadultstravel_purposenationalitydate_of_birthcountry
21/21/241/26/2402private_tripCH7/12/90CH
31/22/241/26/2424private_tripDE5/9/79CH
41/22/241/27/2401private_tripCH11/2/90CH
51/22/242/3/2413private_tripCH2/7/54CH
61/22/241/24/2401private_tripCH3/20/94CH
Input


Output example
Example.xlsx
ABCDEFGHI
1arrivaldeparturechildrenadultstravel_purposenationalitydate_of_birthcountryClass
21/21/241/26/2402private_tripCH7/12/90CHAdult
31/21/241/26/2402private_tripCH7/12/90CHAdult
41/22/241/26/2424private_tripDE5/9/79CHAdult
51/22/241/26/2424private_tripDE5/9/79CHAdult
61/22/241/26/2424private_tripDE5/9/79CHAdult
71/22/241/26/2424private_tripDE5/9/79CHAdult
81/22/241/26/2424private_tripDE5/9/79CHChild
91/22/241/26/2424private_tripDE5/9/79CHChild
101/22/241/27/2401private_tripCH11/2/90CHAdult
111/22/242/3/2413private_tripCH2/7/54CHAdult
121/22/242/3/2413private_tripCH2/7/54CHAdult
131/22/242/3/2413private_tripCH2/7/54CHAdult
141/22/242/3/2413private_tripCH2/7/54CHChild
151/22/241/24/2401private_tripCH3/20/94CHAdult
Output
 
Last edited by a moderator:
Do you have this function in the same module. ie. Put it under the ExtendRows Sub. It is private so it needs to be in the same module

VBA Code:
Private Sub WriteRecord(destRng As Range, rng As Range, recCnt As Long, rowNum As Long, theClass As String)
    destRng.Offset(recCnt, 0) = rng.Offset(rowNum, 0).Value
    destRng.Offset(recCnt, 1) = rng.Offset(rowNum, 1).Value
    destRng.Offset(recCnt, 2) = rng.Offset(rowNum, 2).Value
    destRng.Offset(recCnt, 3) = rng.Offset(rowNum, 3).Value
    destRng.Offset(recCnt, 4) = rng.Offset(rowNum, 4).Value
    destRng.Offset(recCnt, 5) = rng.Offset(rowNum, 5).Value
    destRng.Offset(recCnt, 6) = rng.Offset(rowNum, 6).Value
    destRng.Offset(recCnt, 7) = rng.Offset(rowNum, 7).Value
    destRng.Offset(recCnt, 8) = rng.Offset(rowNum, 8).Value
    destRng.Offset(recCnt, 9) = theClass
End Sub
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Ah ok I didn't understand that, it works now!!

Thank you for all the help.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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