+ Reply to Thread
Results 1 to 13 of 13

Struggling to get VBA code to hide some rows successfully - almost there I think

  1. #1
    Registered User
    Join Date
    12-02-2011
    Location
    Coventry, England
    MS-Off Ver
    Excel 2010
    Posts
    47

    Struggling to get VBA code to hide some rows successfully - almost there I think

    Hi, I have a spreadsheet that has a dropdown in cell E13 with 3 choices - A, B, C

    I have three named ranges;
    Range A rows $3:S5
    Range B rows $6:$10
    Range C rows $11:$15

    If the user chooses A from E13 I would like only Range A rows to show and the others hide, If they choose B only Range B to show and the others hide and if they choose C only Range C to show and the others hide.

    Ive been trying this but Im failing as nothing happens (code is definitely incorrect);

    Please Login or Register  to view this content.
    There may be another way to do this that may be easier so any guidance would be most gratefully appreciated. I may have bitten off more than I can chew...

    Thank you.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    If you are trying to do this automatically when E13 is changed then the sub name should be
    Please Login or Register  to view this content.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    It would be simpler if you simply hid all the rows in the three Ranges first and then unhid the range selected in the drop down list. You should probably be using a Worksheet Change Event handler to monitor the cell ... unless that's what you are doing and passing the Target cell to your routine.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    C looks like it is a reserved name. I had to use D.


    Right Click On Your Sheet Name At the Bottom Of Excel and Select View Code
    Paste this code in the module that opens and close it.

    Please Login or Register  to view this content.


    This works too:

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 07-18-2018 at 03:34 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    Another option, without the need for named ranges
    Please Login or Register  to view this content.
    But are you trying to hide the rows on a different sheet to the dropdown?

  6. #6
    Registered User
    Join Date
    12-02-2011
    Location
    Coventry, England
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    Thank you so much - no the rows are being hidden on the same worksheet...I will give it a try

  7. #7
    Registered User
    Join Date
    12-02-2011
    Location
    Coventry, England
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    I will give this a good go - thank you so much for taking the time.

  8. #8
    Registered User
    Join Date
    12-02-2011
    Location
    Coventry, England
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    Ok sorry to sound a bit thick - but I need to declare the variable MyArray for it to work?

  9. #9
    Registered User
    Join Date
    12-02-2011
    Location
    Coventry, England
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    Quote Originally Posted by Fluff13 View Post
    Another option, without the need for named ranges
    Please Login or Register  to view this content.
    But are you trying to hide the rows on a different sheet to the dropdown?
    I tried this but get a runtime errortype mismatch on the last line - what does the -64 indicate please? thank you again for your help.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    Try
    Please Login or Register  to view this content.
    This makes it case insensitive.

  11. #11
    Registered User
    Join Date
    12-02-2011
    Location
    Coventry, England
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    Quote Originally Posted by mehmetcik View Post
    C looks like it is a reserved name. I had to use D.


    Right Click On Your Sheet Name At the Bottom Of Excel and Select View Code
    Paste this code in the module that opens and close it.

    Please Login or Register  to view this content.


    This works too:

    Please Login or Register  to view this content.
    OOh Ive got a bit further - I tried the first one here and it worked beautifully for the B and D options but as soon as I click the A option it says method "Range" of object_Worksheet failed
    debugger states this line is a problem;
    T = Range(Target.Value).Address
    This is only displayed if I choose the first option A.
    When it does option B and D the cells "flicker"



  12. #12
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    I have attached samples.

    The second example uses A. , B. and C.

    To stop the flickering

    insert the following at Line 4

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    Before the last line.
    Attached Files Attached Files
    Last edited by mehmetcik; 07-18-2018 at 05:22 PM.

  13. #13
    Registered User
    Join Date
    12-02-2011
    Location
    Coventry, England
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Struggling to get VBA code to hide some rows successfully - almost there I think

    That worked an absolute treat! I have been working on it for hours and hours and I can use this coding for so many other things - beyond thrilled. Now to work out how to pull data for each of the fields displayed from a table .. thank you so very much - I am genuinely shocked at how strangers are willing to help people like me. thank you again.

+ 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] Code to hide Rows
    By Excelski in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-14-2018, 04:10 PM
  2. Code to hide Rows
    By Excelski in forum Excel General
    Replies: 0
    Last Post: 05-13-2018, 04:44 AM
  3. Code Stops after runing successfully 90 times.
    By naveenmarapaka in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-05-2018, 10:04 AM
  4. [SOLVED] Code to hide rows
    By MissDB in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-09-2015, 07:31 PM
  5. code for hide rows
    By swfarm in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 04-18-2014, 11:30 AM
  6. I just cannot successfully hide worksheet - want userform only
    By dannyboy1974 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2013, 11:05 PM
  7. Code to hide rows
    By dezmond in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-25-2011, 09:54 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