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
[TABLE="class: cms_table, align: center"]
<tbody>[TR]
[TD]First names[/TD]
[TD]Middle names[/TD]
[/TR]
[TR]
[TD]Penelope[/TD]
[TD]Jill[/TD]
[/TR]
[TR]
[TD]Gwyneth[/TD]
[TD]Diane[/TD]
[/TR]
[TR]
[TD]Alice[/TD]
[TD]Heidi[/TD]
[/TR]
[TR]
[TD]Anna[/TD]
[TD]Lilly[/TD]
[/TR]
[TR]
[TD]Aurora[/TD]
[TD]Victoria[/TD]
[/TR]
</tbody>[/TABLE]



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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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