+ Reply to Thread
Results 1 to 17 of 17

Excel macro code

  1. #1
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Smile Excel macro code

    Hi, I am new to write macro's for excel. I am trying to create a workbook where there is a menu sheet, showing a drop down list of each worksheet. I want to be able to chose one from the list for it then to show that work sheet. Otherwise they will be hidden. Is this possible? Thanks for your help

  2. #2
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Excel macro code

    Hello Tara,

    Could you please upload a sample file.
    Please read the instructions in the gold coloured banner at the top of this page on how to upload a sample file.

    Cheerio,
    vcoolio.

  3. #3
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel macro code

    Hi, thank you for your reply. I have uploaded a sample file. Basically I want to use the "Front Sheet" as a main sheet for a user to see where they would click the drop down list and chose which sheet they need. Then only this sheet plus the front sheet will be visible?
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Excel macro code

    Hello Tara,

    See if this helps:-

    Please Login or Register  to view this content.
    The code above is a Worksheet_Change event and needs to be placed into the sheet module. To implement this code:-

    - Right click on the "Front Sheet" tab.
    - Select "View Code" from the menu that appears.
    - In the big white code field that then appears, paste the above code.

    On selecting a sheet name from the drop down list, the selected sheet will immediately be selected and all the other sheets (excluding the "Front Sheet") will be hidden. So only two sheets will be visible at any time.

    Please note that you have a discrepancy between the sheet name "Screw - Fastener" and the same sheet name in the data validation list. In the sheet name you have a space before and after the "-" but in the data validation list there aren't any spaces. You'll need to adjust one or the other otherwise the code will error on selecting the "Screw - Fastener" name from the drop down.

    I hope that this helps.

    Cheerio,
    vcoolio.

  5. #5
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel macro code

    Hi vcoolio,

    Thank you for your help. I tried the code but it didnt work, nothing happened? I will upload the correct file I am trying to use.

    Thank you

    Tara

  6. #6
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel macro code

    Here is the file

  7. #7
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Excel macro code

    Hello Tara,

    I'm not sure what's going on at your end but the code works exactly as it should in your actual file
    You've correctly changed the cell reference to C6 for the drop down and there aren't any problems on my end.

    Try removing the code, save and close the workbook without the code implemented then open it again and place the code back into the worksheet (Front Sheet) module as per the instructions in post #4.

    Let us know if that helped.

    Cheerio,
    vcoolio.

  8. #8
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel macro code

    Brilliant, it works now. Not sure what I was doing wrong before but I saved and closed like you suggested and it works Thanks so much for your help!

  9. #9
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Excel macro code

    That's excellent Tara!

    You're welcome and I'm glad to have been able to assist.

    Cheerio,
    vcoolio.

    P.S. Directly after this line of code:-

    Please Login or Register  to view this content.
    add this line of code:-
    Please Login or Register  to view this content.
    This will ensure that you don't receive an error message should you ever need to clear a drop down selection.
    Last edited by vcoolio; 01-26-2021 at 06:40 AM. Reason: Add P.S.

  10. #10
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel macro code

    Hi Vcoolio,

    I was just wanting to add in a catergory "ALL" in the drop down list, so when I click this I am able to view all sheets at once. Do you know how I can do this please?

    Thanks
    Tara

  11. #11
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Excel macro code

    Hello Tara,

    Just amend the code as follows:-

    Please Login or Register  to view this content.
    I hope that this helps.

    Cheerio,
    vcoolio.

  12. #12
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel macro code

    Thank you, and if I want to display a new sheet every time called "References", so each time I have front sheet, "Chosen sheet" and references viewable, how to I add this into the code?

    Thanks for your help

  13. #13
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Excel macro code

    Hello Tara,

    Do you mean that you now wish to have a maximum of three sheets visible at any one time? So the Front Sheet and the References sheet are always visible?

    Cheerio,
    vcoolio.

  14. #14
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel macro code

    Yes please if that is possible.

    Thanks
    Tara

  15. #15
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Excel macro code

    Hello Tara,

    The code altered as follows should work for you:-
    Please Login or Register  to view this content.
    The line in red font is the amendment.

    I hope that this helps.

    Cheerio,
    vcoolio.

  16. #16
    Registered User
    Join Date
    01-25-2021
    Location
    Wales
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel macro code

    Perfect! Thanks so much for your help

  17. #17
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Excel macro code

    You're welcome Tara. I'm glad to have been able to assist and thanks for the rep!

    Cheerio,
    vcoolio.

+ 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. Macro code working fine in excel 2013 but not in excel 2010.
    By sere in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2014, 02:23 AM
  2. [SOLVED] Excel Macro Visual Basic code not looking at all sheets with second section of code.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2014, 08:26 AM
  3. Use VBA (excel) to extract only Bold text from excel template. Needing a macro code!!
    By Macgyver123 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-13-2012, 09:57 AM
  4. Importing Excel Macros Code from another Excel sheet which has Macro code.
    By arun.pillai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2010, 05:38 PM
  5. Need Help With Excel Macro Code.
    By realniceguy5000 in forum Excel General
    Replies: 1
    Last Post: 03-20-2008, 03:12 PM
  6. [SOLVED] do anybody have a sample code for executing excel macro from vb code?<eom>
    By B Deepak in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2005, 05:05 AM
  7. Need help with code for Excel Macro
    By mercedes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2005, 12:05 AM

Tags for this Thread

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