+ Reply to Thread
Results 1 to 15 of 15

Hiding Rows using VBA and the values within certain cells

  1. #1
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Hiding Rows using VBA and the values within certain cells

    Hi all, apologies for duplication.

    I am being driven slowly mad by my inability to get a simple piece of code working. I have a calendar that has days acroos the top and race series down the left. I want to be able to hide certain race series that I am not supporting this season by checking a box further down the sheet. For example, if I want to hide all of the rows that contain 'World Series', which is written in cell S161, I want to tick my check box next to this cell and have all rows that start with 'World Series' (in the A column range A1:A181) hidden. When the tick box is unticked, all the World Series rows are shown again.
    This code currently stops and shows a compile error, Next without For. The tick box link cell is X161

    I can supply the sheet if it helps, or a pdf of it so you can see what I am working on.

    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 01-23-2012 at 09:26 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Hiding Rows using VBA and the values within certain cells

    Hi, and welcome to the forum,

    Please note that your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Since you are new I'll edit it for you on this occasion.

    Rather than use a loop to identify rows you wish to hide which can be extremely slow with large ranges, use Data Filter Advanced to filter the list in place on column A for the "s161" value, then have the macro delete all the filtered rows by using the SpecialCells(xlcelltypeVisible) to identify them. This is the fastest and most efficient method I know.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Hiding Rows using VBA and the values within certain cells

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook. Don't upload a picture when you have a workbook question. None of us is inclined to recreate your data. Upload the workbook and manually add an 'after' situation so that we can see what you expect. In addition clearly explain how you get the results..
    To attach a file to your post, you need to be using the main 'New Post' or 'New Thread' page and not 'Quick Reply'.
    To use the main 'New Post' page, click the 'Post Reply' button in the relevant thread.

    On this page, below the message box, you will find a button labelled 'Manage Attachments'.
    Clicking this button will open a new window for uploading attachments.

    You can upload an attachment either from your computer or from another URL by using the appropriate box on this page.
    Alternatively you can click the Attachment Icon to open this page.

    To upload a file from your computer, click the 'Browse' button and locate the file.

    To upload a file from another URL, enter the full URL for the file in the second box on this page.
    Once you have completed one of the boxes, click 'Upload'.

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Hiding Rows using VBA and the values within certain cells

    Hi there,

    Thankyou for responding, apologies for the post format.

    I already tried the advanced filter, and it doesn't really get me the result I am looking for. It would be much more useful to me if I could hide rows that I specify. I am about to upload the file.

    Danny

  5. #5
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Hiding Rows using VBA and the values within certain cells

    Hopefully this is the file attached correctly...

    2012 Events.xlsm

  6. #6
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Hiding Rows using VBA and the values within certain cells

    I already tried the advanced filter, and <<the way I did it>> it doesn't really get me the result I am looking for. It would be much more <<easy for me to understand>> useful to me if I could hide rows that I specify.
    My point is that advanced filter works very well, once you've learned how. I recommend you avoid mandating how the solution is delivered, just explain what you need to achieve.

    One question (following your upload) did you want to delete the hidden rows or just temporarily hide?

    CC
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  7. #7
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Hiding Rows using VBA and the values within certain cells

    Hello there CC,

    I would like to only hide the rows. The plan is that as circumstances change I can look at different series at a time.

  8. #8
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Hiding Rows using VBA and the values within certain cells

    Good, that was what I thought. Irritatingly, my company firewall prevents me from downloading your attachment, but I think your code should be as simple as:

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Hiding Rows using VBA and the values within certain cells

    Good, that was what I thought. Irritatingly, my company firewall prevents me from downloading your attachment, but I think your code should be as simple as:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Hiding Rows using VBA and the values within certain cells

    Hi again,

    I have revised the code a little, no it is just stalling on End If statements, so it must be a syntax error on my part, it seems to me that I am almost there - can someone help me just finish the job off?

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Hiding Rows using VBA and the values within certain cells

    Sorry CC,

    I think we crossed each other, I have read your reply now, and pasted the code in, but it stalls on an expected End With.

    I would ideally like to be able to make the selection dynamic, so instead of "World Series" as the lookup string, I would like to be able to define the contents of a cell - does that make it impossible?

    Thankyou for your help to this point, I am really grateful

    Danny

  12. #12
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Hiding Rows using VBA and the values within certain cells

    This is your code corrected for syntax, but the approach is not good, as explained:
    Please Login or Register  to view this content.
    NB using indentation effectively makes it much easier to see your missing closing statements.

    HTH

  13. #13
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Hiding Rows using VBA and the values within certain cells

    Dear CC,

    It really does, I understand a lot better what is happening now. The only problem I have now is that when I run the macro, it stalls with a run time error 424, says Object required and highlights this line:
    Please Login or Register  to view this content.
    Again, not sure how to solve that?

    Danny

  14. #14
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Hiding Rows using VBA and the values within certain cells

    Further, I am doing something else on the same sheet now because the checkboxes Excel puts in are too small and cannot be resized. But I get the same error, Error 424, Object Required. So I wonder, is this an Excel (VBA) settings thing, or am I just being unlucky. The code is:
    Please Login or Register  to view this content.
    I am so nearly there, please don't give up on me!!

    Danny

  15. #15
    Registered User
    Join Date
    01-16-2012
    Location
    Winslow, England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Hiding Rows using VBA and the values within certain cells

    For anyone reading this thread and needing to know the answer (like me at one stage!), it is below. I haven't got an answer to the checkbox code yet, but hopefully soon will.

    Please Login or Register  to view this content.
    Bit disappointed that the help dried up and I had to go elsewhere, but here is a solution for the next poor soul. Happy programming!

+ 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