+ Reply to Thread
Results 1 to 13 of 13

Macro to unhide & hide rows based on column value

  1. #1
    Registered User
    Join Date
    01-31-2014
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    5

    Macro to unhide & hide rows based on column value

    Hello.

    I would like a buttonclick macro that hides & unhides rows based on cellvalue A2 and col B values.
    This is to use for a sheet I update on a weekly basis, which is supposed to show the last 9 weeks and the current week.

    So when I click the button I need it to hide the last week and unhide the current week, keeping my span of 9 weeks.
    Attached Files Attached Files
    Last edited by qvfr034; 01-31-2014 at 09:11 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: Macro to unhide & hide rows based on column value

    Picture:

    Hi and welcome to the forum

    Please do not upload a picture of your file...rather, upload a sample of your workbook, showing what data you are working with, a few samples of your expected outcome (manually entered is ok) and how you arrived at that. (Exclude sensitive info). Pictures are pretty much impossible to edit, and no-one wants to re-type your data for you. Also, not all members can upload picture files (Company firewalls, etc.)

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    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.
    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
    Registered User
    Join Date
    01-31-2014
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to unhide & hide rows based on column value

    Quote Originally Posted by alansidman View Post
    Picture:

    Hi and welcome to the forum

    Please do not upload a picture of your file...rather, upload a sample of your workbook, showing what data you are working with, a few samples of your expected outcome (manually entered is ok) and how you arrived at that. (Exclude sensitive info). Pictures are pretty much impossible to edit, and no-one wants to re-type your data for you. Also, not all members can upload picture files (Company firewalls, etc.)

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    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.
    Sorry 'bout that, edited and attached my data.
    Last edited by qvfr034; 01-31-2014 at 09:17 AM.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: Macro to unhide & hide rows based on column value

    Need a little bit more information. In the current set up, which rows should be hidden and which ones visible. I don't understand which nine weeks should be visible but last weeks should be hidden. Confused.

  5. #5
    Registered User
    Join Date
    01-31-2014
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to unhide & hide rows based on column value

    Quote Originally Posted by alansidman View Post
    Need a little bit more information. In the current set up, which rows should be hidden and which ones visible. I don't understand which nine weeks should be visible but last weeks should be hidden. Confused.
    The value in A2 represents week 5 2014, hence 405, this value is updated manually each week.
    I want the macro to hide everything (from row 7 and down) >405 in column B and anything more then 9 weeks back from todays week in column B... if that makes any sense..

    With current setup, rows 1 to 6 and rows 54 to 63 would be visible.
    Next week I want rows 1 to 6 and rows 55 to 64 to be visible.
    The week after that rows 1 to 6 and rows 56 to 65..
    etc..
    Last edited by qvfr034; 01-31-2014 at 09:24 AM.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: Macro to unhide & hide rows based on column value

    I got it partially completed. Need to figure out how to get the current 9 weeks visible. Because you change your week numbering at the start of the year, it gets a little more difficult. If you kept the weeks continuous and not change at the end of the year, the current macro would work.

    Please Login or Register  to view this content.
    Am going to seek some additional help on this. Watch for an update.

  7. #7
    Registered User
    Join Date
    01-31-2014
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to unhide & hide rows based on column value

    Quote Originally Posted by alansidman View Post
    I got it partially completed. Need to figure out how to get the current 9 weeks visible. Because you change your week numbering at the start of the year, it gets a little more difficult. If you kept the weeks continuous and not change at the end of the year, the current macro would work.

    Please Login or Register  to view this content.
    Am going to seek some additional help on this. Watch for an update.
    I can live with changing my weeknumbering, so that's not a problem.

    Though I can't seem to get it to unhide week 6 when I enter 406 in A2 and press the button, but it hides the proper weeks back (9).

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: Macro to unhide & hide rows based on column value

    Yeah, Strange.

    Any way, I gave you another macro to unhide all cells.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-31-2014
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to unhide & hide rows based on column value

    Close enough, i'm happy with this solution. Thank you for your help!

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: Macro to unhide & hide rows based on column value

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  11. #11
    Registered User
    Join Date
    08-21-2012
    Location
    Bhubaneswar, Odisha,India
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro to unhide & hide rows based on column value

    Re: Macro to unhide & hide rows based on column value

    I am able to hide the row on one click but unable to unhide the row on second click

    Please advise.

    Code written is as follows:

    Private Sub ToggleButton1_Click()

    Application.ScreenUpdating = False

    For Each Cell In Range("N6:N100")

    Cell.EntireRow.Hidden = Cell.Value = "CLOSED"

    Next Cell

    Application.ScreenUpdating = True

    End Sub

  12. #12
    Registered User
    Join Date
    08-21-2012
    Location
    Bhubaneswar, Odisha,India
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro to unhide & hide rows based on column value

    Uploading the file for necessary correction to the code.
    Attached Files Attached Files

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Macro to unhide & hide rows based on column value

    Quote Originally Posted by Saradindu View Post
    Uploading the file for necessary correction to the code.
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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] Macro to automatically hide or unhide rows based on either a value or no value in a cell
    By WFP111 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2013, 12:28 PM
  2. simple macro to hide or unhide rows based on a cell value
    By Russ Fuquay in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2013, 06:32 PM
  3. [SOLVED] VBA macro that hide and unhide column to respective rows based on first column value
    By janine6192 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2013, 06:21 PM
  4. Macro - Hide/Unhide Rows based on conditional criteria
    By cklein in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2012, 02:23 PM
  5. Macro to Hide/Unhide Rows Based on Results in Column Equation
    By jwhite0720 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2011, 04:59 PM

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