Need help with nested looping

admann96

New Member
Joined
Apr 10, 2018
Messages
1
I have this question:

Create a Sub with any combination of nested loops. This nested loop should take the baby girl names
input (below) and print out every possible combination. These input names will need to appear in your workbook somewhere. Print out the combinations in the workbook itself.
Input
First namesMiddle names
PenelopeJill
GwynethDiane
AliceHeidi
AnnaLilly
AuroraVictoria

<tbody>
</tbody>



I have been able to get Penelope paired with all the middle names, but I can't figure out how to pair the rest of the first names. I don't know how to offset the active cell to the second first name and so on. this is what I have so far:

Sub part2()
Dim combination As String
Dim fName As String
Dim mName As String


Range("A1").Activate
fName = ActiveCell.Value


Do Until IsEmpty(ActiveCell)


mName = ActiveCell.Offset(0, 1).Value
combination = fName & " " & mName
ActiveCell.Offset(0, 3) = combination
ActiveCell.Offset(1, 0).Activate

Loop



 

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.
I'll give you a few clues. No need to use ActiveCell or Offset. The exercise is asking for a nested loop, which is one loop inside another loop. In your case, one loop for column A and another for column B.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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