+ Reply to Thread
Results 1 to 12 of 12

Selection of changing array of sheets via table with selections in sheet 'Index'

  1. #1
    Registered User
    Join Date
    03-17-2017
    Location
    ONES FOREST
    MS-Off Ver
    2016
    Posts
    6

    Post Selection of changing array of sheets via table with selections in sheet 'Index'

    Hi guys!

    I have a workbook made up from these sheets:

    - Index
    - Sheet1
    - Sheet2
    - Sheet3
    - Sheet4
    - Sheet5

    In the sheet 'Index' I have a small table (2 colums) which indicates if the sheet has to be selected in the array or not. The user of the sheet selects 'Yes' or 'No', eg:

    Sheet name: Print:
    - Index No
    - Sheet1 Yes
    - Sheet2 Yes
    - Sheet3 No
    - Sheet4 Yes
    - Sheet5 No

    In this example the sheet array created by the macro should be "Sheet1, Sheet2, Sheet4". In another example it could be "Index, Sheet1, Sheet5", etc.

    I want to create a macro that looks at the table (2 colums) in sheet 'Index' to see if it states 'Yes' or 'No' for the selection and then to make the array needed to print.

    Regards,

    Antoon

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-17-2017
    Location
    ONES FOREST
    MS-Off Ver
    2016
    Posts
    6

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Thanks but it is ALMOST the right answer. I don't want the sheets to be printed. I would like to have the desired sheets SELECTED as being an array. I then want to combine them into 1 PDF-file (I know the PDF code, I just want the code to make the customized selection based on the table.

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-17-2017
    Location
    ONES FOREST
    MS-Off Ver
    2016
    Posts
    6

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Attached a simple example sheet. In the sheet 'Index' i've stated which sheets to select for printing or an export, etc. So the outcome should be that multiple sheets are selected.
    Attached Files Attached Files

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Try this
    Please Login or Register  to view this content.
    Make sure the names listed on the Index sheet exactly match the sheet names (In your example workbook, they do not!)

  7. #7
    Registered User
    Join Date
    03-17-2017
    Location
    ONES FOREST
    MS-Off Ver
    2016
    Posts
    6

    Talking Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Thanks! It worked as a charm. :-)

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Thanks a lot dangelor for this great code ...
    Just curious question : Why using boolean variable and using it in this part of Replace:=Not b then to b=True
    I have tried the code and put Replace:=False .. And removed this boolean variable and the code worked well too
    Is there a trick in using this variable in that way?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  9. #9
    Registered User
    Join Date
    03-17-2017
    Location
    ONES FOREST
    MS-Off Ver
    2016
    Posts
    6

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    One additional question. The code mentioned works perfectly but what if I decide to hide or remove one sheet? So the table (see picture before) will stay intact but the actual sheets don't.

    Where do I place an error code to try the following line (meaning: trying to select the next sheet which is not hidden (or maybe it is too)).

    Sub SelectSheetsArray()
    Dim v As Variant
    Dim a As Long
    Dim b As Boolean

    With Sheets("Index")
    v = .Range("A1:B" & .Cells(Rows.Count, 2).End(xlUp).Row)
    For a = LBound(v) To UBound(v)
    If v(a, 2) = "Yes" Then Sheets(v(a, 1)).Select Replace:=Not b: b = True
    Next a
    End With
    End Sub

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    May be
    Please Login or Register  to view this content.

  11. #11
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Quote Originally Posted by YasserKhalil View Post
    Thanks a lot dangelor for this great code ...
    Just curious question : Why using boolean variable and using it in this part of Replace:=Not b then to b=True
    I have tried the code and put Replace:=False .. And removed this boolean variable and the code worked well too
    Is there a trick in using this variable in that way?
    That bit of logic stops the active sheet from being added to the array.

  12. #12
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Selection of changing array of sheets via table with selections in sheet 'Index'

    Quote Originally Posted by a.vanmil View Post
    One additional question. The code mentioned works perfectly but what if I decide to hide or remove one sheet? So the table (see picture before) will stay intact but the actual sheets don't.

    Where do I place an error code to try the following line (meaning: trying to select the next sheet which is not hidden (or maybe it is too)).

    Sub SelectSheetsArray()
    Dim v As Variant
    Dim a As Long
    Dim b As Boolean

    With Sheets("Index")
    v = .Range("A1:B" & .Cells(Rows.Count, 2).End(xlUp).Row)
    For a = LBound(v) To UBound(v)
    If v(a, 2) = "Yes" Then Sheets(v(a, 1)).Select Replace:=Not b: b = True
    Next a
    End With
    End Sub
    As long as any sheet name exists and has a Yes, it will run. It ignores any sheet with a No.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA - Create New Sheets Based on Index Sheet Cell Values with Link to Index Sheet
    By order in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-02-2017, 06:23 PM
  2. Generate sheet using selections from other sheets
    By danieloverton1984 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-12-2016, 05:35 AM
  3. Combobox Selections to paste cell selection across sheets.
    By ltjackson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2015, 05:41 PM
  4. [SOLVED] lookup the sheet without changing the source sheet in table array look up
    By Did13n in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-10-2015, 01:33 AM
  5. Index Function with changing array
    By starcraftbud in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-13-2010, 11:42 AM
  6. Sheets Array Selection
    By JJ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2006, 01:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1