Create worksheet for All Possible combination in the same row

shelim481

New Member
Joined
Aug 30, 2018
Messages
28
Hi, how would i go about creating worksheets for every possible combination of data. but the data is in the same row, only separated by by one blank row... there are significantly more then shown below..

x1
x2
x3

y1
y2

the tabs (new worksheet) should be created is
x1-y1
x2-y1
x3-y1
x1-y2



thanks
x2-y2
x3-y2
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Test with EXACTLY the same layout as in my example (which is based on your data)
Run from the same sheet
Excel 2016 (Windows) 32 bit
A
1
2
x1
3
x2
4
x3
5
6
y1
7
y2
8
Sheet: XX


Code:
Sub InsertSheets()
    Dim rng1 As Range, rng2 As Range, c1 As Range, c2 As Range

    Set rng1 = Range("A2", Range("A2").End(xlDown))
    Set rng2 = Range("A" & Rows.Count).End(xlUp)
    Set rng2 = Range(rng2, rng2.End(xlUp))
   
    For Each c1 In rng1
        For Each c2 In rng2
            On Error Resume Next
                ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
                WorkSheets(WorkSheets.Count).Name = c1 & "-" & c2
        Next c2
    Next c1
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,693
Messages
6,126,242
Members
449,304
Latest member
hagia_sofia

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