+ Reply to Thread
Results 1 to 2 of 2

Hide sheets in a Bill of Material

  1. #1
    Registered User
    Join Date
    04-17-2013
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 207
    Posts
    1

    Hide sheets in a Bill of Material

    I have created a workbook that generates a complete bill of material for a selected model by un-hiding specified worksheets. Each worksheet contains a sub-assembly that is relevant to the user selected model. However, some selected models do not contain all sub-assemblies, which is where the issue occurs. If a user generates a bill of material for a model containing all sub-assemblies, the macro will un-hide all pertinent sub-assemblies without issue. Then if the user selects another model that does not contain all sub-assemblies and generates a bill of material, sub-assembly worksheets from the first generated bill of material remain un-hidden. What is the best way to hide worksheets leftover from the prior generation by the user. The code thus far is as follows:

    Sub GetSheets()

    On Error Resume Next
    numwrksheets = ActiveWorkbook.Worksheets.Count
    w = 1
    For w = 1 To numwrksheets
    Worksheets(w).Visible = False
    Next w

    Worksheets("MODEL SELECTION SHEET").Visible = True

    Excel.Worksheets("MODEL SELECTION SHEET").Activate
    selectedmodel = Excel.ActiveSheet.Range("P1").Text
    'x = MsgBox(model, vbOKCancel, "variable content")
    Excel.Worksheets("index").Activate

    n = 1

    For n = 1 To 24

    rnge = "A" & n

    model = ActiveSheet.Range(rnge).Text

    If selectedmodel = model Then Row = n
    Next n

    Excel.Worksheets((ActiveSheet.Range(("B" & Row)).Text)).Visible = True
    Excel.Worksheets((ActiveSheet.Range(("C" & Row)).Text)).Visible = True
    Excel.Worksheets((ActiveSheet.Range(("D" & Row)).Text)).Visible = True
    Excel.Worksheets((ActiveSheet.Range(("E" & Row)).Text)).Visible = True
    Excel.Worksheets((ActiveSheet.Range(("F" & Row)).Text)).Visible = True
    Excel.Worksheets((ActiveSheet.Range(("G" & Row)).Text)).Visible = True
    Excel.Worksheets((ActiveSheet.Range(("H" & Row)).Text)).Visible = True
    Excel.Worksheets((ActiveSheet.Range(("I" & Row)).Text)).Visible = True

    Excel.Worksheets("index").Visible = False

    End Sub

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Hide sheets in a Bill of Material

    Hi,

    try this:
    Please Login or Register  to view this content.
    like used in this example: Hide sheets in a Bill of Material.xlsm

    Mark this thread SOLVED if this answer solved this problem.

    Regards
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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