Print all combinations from a drop down list onto a pdf or a new excel sheet

Ankit Chowdhary

New Member
Joined
Apr 5, 2022
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi Experts,

Need help to print all combinations from a drop down list onto a pdf or a new excel sheet which will have all combinations in different sheets.

Just to explain. I have three sheets (1. NSV, 2. Volumes 3. NSV per ton) and have 2 data validation drop downs with the below combinations:

1. Arivia, Retail, Total
2. Core, FS, Total

Hence there are 9 combinations, and 3 sheets, so total of 27 pdfs should come up but all should be in one pdf file or we can also have 27 new sheets in a new excel file with all the combinations. Quick help is needed pls.

I was asked to refer to a solution but that is very different from my ask.. Request your help here as its very time consuming for me right now.

1649225118520.png
1649225124492.png
1649225133210.png
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
as starter because your explanation is vague
you can add a 3rd loop with the sheets to have 27 combinations
VBA Code:
Sub comb()
     For Each it1 In Array("Arivia", "Retail", "Total")
          For Each it2 In Array("Core", "FS", "Total")
               Sheets.Add(After:=Sheets(Sheets.Count)).Name = it1 & "_" & it2     'add a new sheet with that name
               s = s & IIf(Len(s) > 0, "|", "") & it1 & "_" & it2
               ActiveSheet.Range("A1") = "this is sheet " & it1 & "_" & it2
          Next
     Next

     sp = Split(s, "|")                                         'array with the new names
     Sheets(sp).PrintPreview                                    'printpreview of all new sheets
End Sub
 
Upvote 0
The above code gave 9 sheets with data mentioned "this is sheet XXXXX"

Sorry for being vague, will try and explain to the best of my ability.

I have data in 3 sheets namely - NSV, Volume and NSV per tonne and the combinations for each sheets are mentioned above Arivia, Retail, Total and Core, FS, Total

Hence for each sheet there is 9 combinations. If I could get the data from the sheets as well it would be great. Currently 9 blank sheets has come up. Instead 9 sheets for NSV, 9 sheets for Volume and 9 sheets NSV per tonne should come with the above combinations.

Hope i made myself clear. In case I can show the sheet over screenshare on my gmail id

ankitchowdhary63466@gmail.com

Let me know. Thanks for the help.
 
Upvote 0
VBA Code:
Sub comb2()
     For Each sh In Array("NSV", "Volumes", "NSV per tonne")
          k = 0
          For Each it1 In Array("Arivia", "Retail", "Total")
               For Each it2 In Array("Core", "FS", "Total")
                    s0 = sh & "_" & it1 & "_" & it2
                    Sheets.Add(After:=Sheets(Sheets.Count)).Name = s0     'add a new sheet with that name (=total 27)
                    s = s & IIf(Len(s) > 0, "|", "") & s0
                    ActiveSheet.Range("A1") = "this is sheet " & s0
                    k = k + 1
                    Sheets(sh).Range("A" & k).Value = s0        'int the original 3 sheets, write the list in A1 & next
               Next
          Next
     Next

     sp = Split(s, "|")                                         'array with the new names

     Sheets(sp).Move                                            'those 27 new added sheets to a new workbook
     ActiveWorkbook.SaveAs "book_" & Format(Now, "yyyymmdd_hhmmss")     'save that new workbook as ...
     ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Data\Stal_Excell\Map1.pdf"     'export that workbook to a pdf

     Sheets(sp).PrintPreview                                    'printpreview of all new sheets
End Sub
 
Upvote 0
Hi BSALV,

Thanks for the quick response. With the above code, i am getting all 27 sheets in a separate excel file but the challenge is that the sheets are blank.

The respective data of each filters is not getting moved.

Can you pls help.

1649231807213.png
 
Upvote 0
Assum your current workbook name is "Old". Below code will dupplicate each sheet 9 times, with 9 combination of cell C2 and C3
New workbook, with 1 original sheet1 plus 27 new sheets, named like this: "NPV 1-1","NPV 1-2" ..., with cell C2 and C3 display combination.
VBA Code:
Option Explicit
Sub split()
Application.ScreenUpdating = False
Dim drop1, drop2, i&, j&, ws As Worksheet
drop1 = Array("Core", "Arivia", "Total") ' option list in cell C2
drop2 = Array("Retail", "FS", "Total") ' option list in cell C3
Workbooks.Add
    For Each ws In Workbooks("Old").Sheets 'assume workbook with data, named "Old", adjust to actual name
        For i = 0 To 2
            For j = 0 To 2
                ws.Copy after:=Sheets(Sheets.Count)
                With ActiveSheet
                    .Range("C2").Value = drop1(i)
                    .Range("C3").Value = drop2(j)
                    .Name = ws.Name & " " & i + 1 & "-" & j + 1
                End With
            Next
        Next
    Next
Application.ScreenUpdating = True
End Sub

Capture.JPG
Capture2.JPG
 
Upvote 0
For the purpose I changed my sheet name to "Old" and then pasted the above code.

Its throwing the below error and I did Yes to all around 10-15 times and then the excel got stuck.

Anything that I am doing wrong here.

1649233692459.png
 
Upvote 0
Hi.. Its still not working .. I changed the workbook to "Old" but the excel is frozen and need to restart it.
 
Upvote 0

Forum statistics

Threads
1,215,442
Messages
6,124,886
Members
449,194
Latest member
ronnyf85

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