+ Reply to Thread
Results 1 to 4 of 4

Hide and delete sheets based on cell input

Hybrid View

  1. #1
    Registered User
    Join Date
    07-21-2014
    Location
    Kuala lumpur, malaysia
    MS-Off Ver
    2010
    Posts
    7

    Hide and delete sheets based on cell input

    Hi,

    I am fairly new in vba.

    I have a situation where i would like to hide and delete a few sheets in my worksheet.

    there is a few sheets where i want it to be constantly visible and one sheet is based on a cell reference.

    the remaining irrelevant sheets i would like it to be hidden and deleted.

    How do i go about this?

    'always visible are sheets that are constantly visible in all files'
    'visible msds is the sheet where my product data is being pulled out based on a input i enter on my first sheet'
    the sheets i want to hide and delete will be the remaining irrelevant "MSDS" that i would like to remove through macro.

    Sub hide()
    
    'always visible'
    
    Worksheets("Input").Visible = xlSheetVisible
    Worksheets("Check sheet").Visible = xlSheetVisible
    Worksheets("Component Description").Visible = xlSheetVisible
    
    'visible msds'
    
    Dim rng As Range
    Dim wks As Worksheet
    
    Set rng = Sheets("Input").Range("B3")
    Set wks = Sheets(rng.Value)
    wks.Visible = xlSheetVisible


    Thanks guys,

    Hopefully you all can help me in this.
    Last edited by alansidman; 08-11-2014 at 11:12 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,716

    Re: Hide and delete sheets based on cell input

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,716

    Re: Hide and delete sheets based on cell input

    Try this:

    Option Explicit
    Sub hide()
    
    'always visible'
    
    Worksheets("Input").Visible = xlSheetVisible
    Worksheets("Check sheet").Visible = xlSheetVisible
    Worksheets("Component Description").Visible = xlSheetVisible
    
    'visible msds'
    
    Dim rng As Range
    Dim wks As Worksheet
    
    Set rng = Sheets("Input").Range("B3")
    Set wks = Sheets(rng.Value)
    wks.Visible = xlSheetVisible
    
    Application.DisplayAlerts = False
    
    For Each wks In Worksheets
        If wks.Name <> "Input" And wks.Name <> "Check sheet" And wks.Name <> "Componwent Description" And wks.Name <> rng Then
            wks.Delete
        End If
    Next wks
    Application.DisplayAlerts = True
    End Sub

  4. #4
    Registered User
    Join Date
    07-21-2014
    Location
    Kuala lumpur, malaysia
    MS-Off Ver
    2010
    Posts
    7

    Re: Hide and delete sheets based on cell input

    Hi alansidman,

    That worked like a charm.

    Thanks a lot for the help.


+ 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. How to auto hide/unhide sheets in excel workbook based on cell input?
    By bensaps10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-02-2014, 09:57 AM
  2. [SOLVED] hide sheets based on the cell value
    By sknalodz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-24-2013, 01:43 AM
  3. [SOLVED] Show / Hide Sheets based off a cell input
    By evancharles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-16-2012, 09:35 AM
  4. Hide / Delete rows based on value in cell
    By lgimnich in forum Excel General
    Replies: 2
    Last Post: 06-30-2012, 09:52 AM
  5. Hide sheets based on cell value input
    By EdMac in forum Excel General
    Replies: 10
    Last Post: 11-17-2006, 06:01 AM

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