+ Reply to Thread
Results 1 to 12 of 12

reduce part code and simple it.

Hybrid View

ninhmoon reduce part code and simple... 06-08-2015, 09:39 PM
protonLeah Re: reduce part code and... 06-08-2015, 10:31 PM
ninhmoon Re: reduce part code and... 06-08-2015, 10:56 PM
SamT Re: reduce part code and... 06-08-2015, 10:55 PM
ninhmoon Re: reduce part code and... 06-08-2015, 11:03 PM
SamT Re: reduce part code and... 06-08-2015, 11:25 PM
ninhmoon Re: reduce part code and... 06-08-2015, 11:38 PM
protonLeah Re: reduce part code and... 06-09-2015, 07:47 PM
ninhmoon Re: reduce part code and... 06-10-2015, 12:31 AM
SamT Re: reduce part code and... 06-10-2015, 08:46 AM
6StringJazzer Re: reduce part code and... 06-10-2015, 05:14 PM
SamT Re: reduce part code and... 06-10-2015, 07:03 PM
  1. #1
    Registered User
    Join Date
    04-07-2015
    Location
    Vietnam
    MS-Off Ver
    Office 2013
    Posts
    89

    reduce part code and simple it.

    Hi All!
    I have a part code bellow:

    Sub annhieusheetS()
    Sheets("Home").Visible = xlVeryHidden
    Sheets("Notecong (2)").Visible = xlVeryHidden
    Sheets("5 ngày+6thang ").Visible = xlVeryHidden
    Sheets("Payroll(G1)").Visible = xlVeryHidden
    'Sheets("Group3").Visible = xlVeryHidden
    Sheets("Company payment").Visible = xlVeryHidden
    Sheets("Payroll(G3)").Visible = xlVeryHidden
    Sheets("04.2015").Visible = xlVeryHidden
    'Sheets("Diemchuyen").Visible = xlVeryHidden
    'Sheets("OVER1").Visible = xlVeryHidden
    Sheets("PL(G1) (2)").Visible = xlVeryHidden
    Sheets("PL(G2) (2)").Visible = xlVeryHidden
    Sheets("PL(G3) (2)").Visible = xlVeryHidden
    'Sheets("an ca tháng ").Visible = xlVeryHidden
    'Sheets("OVER2").Visible = xlVeryHidden
    'Sheets("OVER3").Visible = xlVeryHidden
    Sheets("Employ payment").Visible = xlVeryHidden
    'Sheets("Group1").Visible = xlVeryHidden
    'Sheets("Group2").Visible = xlVeryHidden
    Sheets("Tru tien com trua").Visible = xlVeryHidden
    Sheets("TOTAL -April-2015").Visible = xlVeryHidden
    Sheets("Bang ke Tien").Visible = xlVeryHidden
    Sheets("slr man-In").Visible = xlVeryHidden



    End Sub
    Sub hiennhieusheetS()
    Sheets("Home").Visible = True
    Sheets("Notecong (2)").Visible = True
    Sheets("5 ngày+6thang ").Visible = True
    Sheets("Payroll(G1)").Visible = True
    Sheets("Group3").Visible = True
    Sheets("Company payment").Visible = True
    Sheets("Payroll(G3)").Visible = True
    Sheets("04.2015").Visible = True
    Sheets("Diemchuyen").Visible = True
    Sheets("OVER1").Visible = True
    Sheets("PL(G1) (2)").Visible = True
    Sheets("PL(G2) (2)").Visible = True
    Sheets("PL(G3) (2)").Visible = True
    'Sheets("an ca tháng ").Visible = xlVeryHidden
    Sheets("OVER2").Visible = True
    Sheets("OVER3").Visible = True
    Sheets("Employ payment").Visible = True
    Sheets("Group1").Visible = True
    Sheets("Group2").Visible = True
    Sheets("Tru tien com trua").Visible = True
    Sheets("TOTAL -April-2015").Visible = True
    Sheets("Bang ke Tien").Visible = True
    Sheets("slr man-In").Visible = True

    End Sub
    Please Help me!

    How to write short code to easy to see and simple understand it.
    And I have question:
    When I delete a sheet in the file so What Do I write for the code update the sheets I want to hide or unhide it.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: reduce part code and simple it.

    Option Explicit
    Sub annhieusheetS()
        Dim MySheets As Variant
        Dim Sht As Variant
        
        MySheets = Array("Home", "Notecong (2)", "5 ngày+6thang ", "Payroll(G1)", "Company payment", _
                        "Payroll(G3)", "04.2015", "PL(G1) (2)", "PL(G2) (2)", "PL(G3) (2)", _
                        "Employ payment", "Tru tien com trua", "TOTAL -April-2015", _
                        "Bang ke Tien", "slr man-In")
        
        For Each Sht In MySheets
            Sht.Visible = xlVeryHidden
        Next Sht
    End Sub
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    04-07-2015
    Location
    Vietnam
    MS-Off Ver
    Office 2013
    Posts
    89

    Re: reduce part code and simple it.

    Quote Originally Posted by protonLeah View Post
    Option Explicit
    Sub annhieusheetS()
        Dim MySheets As Variant
        Dim Sht As Variant
        
        MySheets = Array("Home", "Notecong (2)", "5 ngày+6thang ", "Payroll(G1)", "Company payment", _
                        "Payroll(G3)", "04.2015", "PL(G1) (2)", "PL(G2) (2)", "PL(G3) (2)", _
                        "Employ payment", "Tru tien com trua", "TOTAL -April-2015", _
                        "Bang ke Tien", "slr man-In")
        
        For Each Sht In MySheets
            Sht.Visible = xlVeryHidden
        Next Sht
    End Sub
    I don't know what is happen with your code.
    It appear a error bellow:
    http://i.imgur.com/5U8iztd.png

  4. #4
    Registered User
    Join Date
    11-13-2006
    Posts
    87

    Re: reduce part code and simple it.

    If you wish to exempt one or two sheets
    Sub SamT_HideSheets()
    Dim Sht As Worksheet
    
    For Each Sht in Sheets
       If Not Sht.Name = "sheet1" Or Sht.Name = "sheet2" Then  Sht.Visible = xlVeryHidden
    Next Sht
    End Sub

  5. #5
    Registered User
    Join Date
    04-07-2015
    Location
    Vietnam
    MS-Off Ver
    Office 2013
    Posts
    89

    Re: reduce part code and simple it.

    Quote Originally Posted by SamT View Post
    If you wish to exempt one or two sheets
    Sub SamT_HideSheets()
    Dim Sht As Worksheet
    
    For Each Sht in Sheets
       If Not Sht.Name = "sheet1" Or Sht.Name = "sheet2" Then  Sht.Visible = xlVeryHidden
    Next Sht
    End Sub
    thanks your code.
    So when I change your code to hidden the code:
    Sub SamT_unShowSheets()
    Dim Sht As Worksheet
    
    For Each Sht In Sheets
       
       If Not Sht.Name = "sheet1" Or Sht.Name = "sheet2" Then Sht.Visible = xlHidden
    Next Sht
    End Sub
    over. I use the button F8 to play the line code.
    So then sht.visible = xlhidden
    it fill yellow, it break code.
    Please explain for me what is happen with the code bellow.
    Thanks

  6. #6
    Registered User
    Join Date
    11-13-2006
    Posts
    87

    Re: reduce part code and simple it.

    There is no xlHidden
    There is only
    • True
    • False
    • xlVisible
    • xlVeryHidden


    You can try
    • xlSheetHidden
    • xlSheetVisible
    • xlsheetVeryHidden


    But I never have used those three.

  7. #7
    Registered User
    Join Date
    04-07-2015
    Location
    Vietnam
    MS-Off Ver
    Office 2013
    Posts
    89

    Re: reduce part code and simple it.

    Quote Originally Posted by SamT View Post
    There is no xlHidden
    There is only
    • True
    • False
    • xlVisible
    • xlVeryHidden


    You can try
    • xlSheetHidden
    • xlSheetVisible
    • xlsheetVeryHidden


    But I never have used those three.
    I try to use all methods.
    But it break code with error
    http://i.imgur.com/c5jWFad.png
    So I don't know why.

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: reduce part code and simple it.

    Option Explicit
    Sub annhieusheetS()
    Dim MySheets As Variant
    Dim Sht As Variant

    MySheets = Array("Home", "Notecong (2)", "5 ngày+6thang ", "Payroll(G1)", "Company payment", _
    "Payroll(G3)", "04.2015", "PL(G1) (2)", "PL(G2) (2)", "PL(G3) (2)", _
    "Employ payment", "Tru tien com trua", "TOTAL -April-2015", _
    "Bang ke Tien", "slr man-In")

    For Each Sht In MySheets
    sheets(Sht).Visible = xlVeryHidden
    Next Sht
    End Sub

  9. #9
    Registered User
    Join Date
    04-07-2015
    Location
    Vietnam
    MS-Off Ver
    Office 2013
    Posts
    89

    Re: reduce part code and simple it.

    Quote Originally Posted by protonLeah View Post
    Option Explicit
    Sub annhieusheetS()
    Dim MySheets As Variant
    Dim Sht As Variant

    MySheets = Array("Home", "Notecong (2)", "5 ngày+6thang ", "Payroll(G1)", "Company payment", _
    "Payroll(G3)", "04.2015", "PL(G1) (2)", "PL(G2) (2)", "PL(G3) (2)", _
    "Employ payment", "Tru tien com trua", "TOTAL -April-2015", _
    "Bang ke Tien", "slr man-In")

    For Each Sht In MySheets
    sheets(Sht).Visible = xlVeryHidden
    Next Sht
    End Sub
    THanks I understood. what's happen with my file. because some name sheet has not in the file.
    Thanks!
    The second request:
    I want to ask:
    I want to hidden sheets, but I do not the name sheets.
    So How I can hidden the sheets in the file immediately?

  10. #10
    Registered User
    Join Date
    11-13-2006
    Posts
    87

    Re: reduce part code and simple it.

    Sub Test()
    Dim Sht As Worksheet
    
    For Each Sht In Sheets
    'Must leave one sheet visible
    If Sht.Name <> "Home" Then Sht.Visible = xlSheetVeryHidden
    Next
    
    annhieusheetS 'Show named sheets
    End Sub
    Last edited by SamT; 06-10-2015 at 09:11 AM.

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,769

    Re: reduce part code and simple it.

    ninhmoon, please take the time to review our rules. There aren't many, and they are all important.

    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 here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  12. #12
    Registered User
    Join Date
    11-13-2006
    Posts
    87

    Re: reduce part code and simple it.

    I have heard of rule nazis, but you are freaking me out. There's been 10 responses here already.

    But, it reminds me again why I only have 86 posts here in a decade.

    You tell simon and the guys hi for me why don'cha. 'cuz I am outa here again.

    If you ever visit VBA Express, gimmee a holler now.

    SamT
    Last edited by SamT; 06-10-2015 at 07:15 PM.

+ 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. Replies: 2
    Last Post: 03-09-2013, 04:30 AM
  2. how can i reduce this code
    By newapa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2012, 04:44 AM
  3. Reduce Redundant Code Help Please
    By Hummuna in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-11-2012, 09:09 AM
  4. Reduce Runtime For This Code
    By moo5003 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2011, 04:56 PM
  5. Reduce block of code
    By khalid79m in forum Excel General
    Replies: 2
    Last Post: 03-16-2007, 10:08 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