Making Array From Checkboxs

Mr_N0body

New Member
Joined
Jul 21, 2021
Messages
3
Office Version
  1. 365
Hi,
I've been searching for code to fit what I'm doing, but I can't find it. I've found a lot of stuff that's close, but I haven't figured out how to adapt it so I'm hoping someone can kindly assist me.

What I'm trying to do:

Export sheets from a workbook as PDF based on checkboxes that are selected

Problem:

Using if statements and concatenate I can create the array that I need in a cell (see images). So excel D203 contains the array, but I can't figure out how to feed it in to the Sheets(Array(4, 5, 6, 7)).Select code to replace the 4,5,6,7. I basically need it to say Sheets(Array(whatever array is in cell D203)).Select.

Here is the code that I have
VBA Code:
Sub Button4_Click()

Dim v As Variant

v = Application.GetSaveAsFilename("Generic Filename.pdf", "PDF Files (*.pdf), *.pdf")

If VarType(v) = vbString Then
Sheets(Array(4, 5, 6, 7)).Select
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=v, _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, OpenAfterPublish:=True
End If

End Sub
 

Attachments

  • 1.JPG
    1.JPG
    24.9 KB · Views: 8
  • 2.JPG
    2.JPG
    21.3 KB · Views: 8
  • 3.JPG
    3.JPG
    46.8 KB · Views: 8
  • 4.JPG
    4.JPG
    51.7 KB · Views: 8

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
See whether this helps ...

VBA Code:
Sub Button4_Click()

    Dim v As Variant, Rng As Range, arr As Variant

    v = Application.GetSaveAsFilename("Generic Filename.pdf", "PDF Files (*.pdf), *.pdf")

    If VarType(v) = vbString Then
        Set Rng = ThisWorkbook.Sheets("Sheet1").Range("D203")   ' <<< change sheet name and range address to suit
        arr = VBA.Split(Rng.Value, ",")
        Sheets(arr).Select
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=v, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                                        IgnorePrintAreas:=False, OpenAfterPublish:=True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,147
Members
449,364
Latest member
AlienSx

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