+ Reply to Thread
Results 1 to 13 of 13

Hide rows in worksheet with dependency on variable in cel

  1. #1
    Registered User
    Join Date
    08-25-2013
    Location
    Amstelveen, Holland
    MS-Off Ver
    Excel 2010
    Posts
    5

    Hide rows in worksheet with dependency on variable in cel

    Hi
    I'd like to achieve the following in essence:

    if the value on Sheet 1 in cel A1 = No, then rows 41 up to and including 45 of Sheet 1 should be hided.
    (if cel A1 changes back into 'No' the rows 41 up to and including 45 should show)

    Then later on it should be developped in:
    if the value of one of the cels in A1 or B1 or C1 = No, the rows should be hided
    if the value of cel A1 = No the rows on Sheet 2 should be hided.
    (but I am sure that I can work this out, once I understand the basic code)

    If tried to search to the Q&A on this forum, (and watched several video's) but cannot combine the answers to a solution that works for me. I am just starting using vba so excuse my lack of knowledge to it

    If someone could provide me with a basic code, I would be very grateful.

    An additional question : can I also use the 'veryhidden' on rows? Or is this for hiding worksheets only?

    Thank you in advance for helping me.

    Judith

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Hide rows in worksheet with dependency on variable in cel

    Hi, Judith,

    this code will only work for a manual entry into A1 of Sheet1. Right click on the Worksheet tab, choose View Code and paste the code into the code window:
    Please Login or Register  to view this content.
    Code will work only if one cell is edited, will check for A1 to be the cell to be edited, and then decide whether or not to hide the rows 41 to 45.

    The command you found will only work for worksheets.not for rows.

    If you want to have more cells like A1 to C1 you must make sure if theses cells should be looked upon indepently from each other (change Range("A1") to Range("A1:C1")) or should operate together (all must show either Yes or No).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    08-25-2013
    Location
    Amstelveen, Holland
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Hide rows in worksheet with dependency on variable in cel

    ciao Holger,

    Thanks for answering:

    I tried... but I cannot get it working.
    first the value in A1 is not a manual input but a result of a formula. BUt if set that beside and put manually No in cel A1, it still does not hide the rows....
    The name of the sheet is '4' I don't know if that is info you need?

    Wat does the 'target.count' do?

    I was thinking more like of an if function like below:
    if cel A1 = "No" then Rows("41:45").Hidden

    I think I can work around that A1 should be a manual input. By copy cel a1 and past it as a value in A2 en then referring the formula to A2?
    Last edited by Juut; 08-25-2013 at 12:51 PM.

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

    Re: Hide rows in worksheet with dependency on variable in cel

    Let me explain how you should approach this.

    What you need is a macro that runs when you change A1, B1 or C1 of a specific spread sheet.

    So you need a sheet specific macro that is triggered by a change event.

    So Right click on the sheet name of the sheet in question and select view code.

    A window opens there are two list boxes.

    On the one on the left choose Worksheet

    On the one on the right choose Change

    you will have something like this:-



    Please Login or Register  to view this content.
    This will run anytime you make a change in that specific worksheet.

    So any code we run will be sheet specific.

    Next we need to ensure that our bit of code only runs if A1, B1 or C1 are changed.


    You need a bit of code like this:-

    Please Login or Register  to view this content.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Hide rows in worksheet with dependency on variable in cel

    Hi, Judith,

    no problem:
    Please Login or Register  to view this content.
    This code evaluates if the Range A1 shows Yes (delivers False, rows will be visible) or No (delivers True, Rows will be hidden).

    Target.Count counts the number of cells which are being changed - you may mark cells prior to entering and close instead of just Enter with CTRL+ENTER to fill into mulitple cells.

    Maybe have a look at the workbook attached, first worksheet for manual entry, second for change of formula.

    Ciao,
    Holger
    Attached Files Attached Files
    Last edited by HaHoBe; 08-25-2013 at 01:00 PM.

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

    Re: Hide rows in worksheet with dependency on variable in cel

    Judith

    Cell A1, A2, A3 must be "No" not "no" or "nO" unless you wrap Lcase() around the equations so that you are looking for "no"

    The change can be manual, Typed or a formula or input by a userform. [ Not the Excel Data Entry Userform].

    Please Login or Register  to view this content.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Hide rows in worksheet with dependency on variable in cel

    Hi, mehmetcik,

    maybe think about

    Please Login or Register  to view this content.
    being a bit of overkill - Rows equals the entire row AFAIK.

    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    08-25-2013
    Location
    Amstelveen, Holland
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Hide rows in worksheet with dependency on variable in cel

    Thanks for your example Holger, looks clear to me, but I cannot get it working in mine.
    I attached the worksheet concerning, would you be so kind to give it a look and tell me where I go wrong?
    Attached Files Attached Files

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Hide rows in worksheet with dependency on variable in cel

    Hi, Judith,

    UCase (Upper Case) changes Yes to YES - please change the code to read
    Please Login or Register  to view this content.
    Ciao,
    Holger

  10. #10
    Registered User
    Join Date
    08-25-2013
    Location
    Amstelveen, Holland
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Hide rows in worksheet with dependency on variable in cel

    Thanks I have seen it working now once....

    after I make it YES in the code it worked

    I tried again:
    and then excel stopped working......
    and when it does not stop working it gves a Runtime error:

    "Method "hidden' of aobject "Range 'failed
    Last edited by Juut; 08-25-2013 at 02:22 PM.

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Hide rows in worksheet with dependency on variable in cel

    Hi, JuŽdith,

    to be honest: I would not rely on the Worksheet_Calculate-Event but take the Worksheet_Change-Event for Range C20 and C25 (check for the value in C28 from there) instead as these cells directly influence the formula in C26 as well as C28 and may be taken to trigger the macro.

    Ciao,
    Holger

  12. #12
    Registered User
    Join Date
    08-25-2013
    Location
    Amstelveen, Holland
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Hide rows in worksheet with dependency on variable in cel

    How would that look then?
    I remember you started with the Worksheet_Change event, but later on we went to Worksheet_Calculate.

  13. #13
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Hide rows in worksheet with dependency on variable in cel

    Hi, Judith,

    sorry but I was wrong about the cells which need to be monitored. Worksheet_Change-Event may look like this:
    Please Login or Register  to view this content.
    You should use only one of these events, not both for the very same sheet.

    Ciao,
    Holger

+ 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. Hide Multiple Rows Based upon a variable
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-22-2012, 01:03 PM
  2. custom worksheet function and calculation dependency
    By dlh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2010, 06:14 PM
  3. Macros to hide variable rows in an array
    By Dr Bob in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-26-2009, 07:02 AM
  4. [SOLVED] Passing formula value to variable, hide rows
    By Punsterr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2006, 08:40 PM
  5. 1-variable Data Table w/ dependency on MS Query fails to update correctly
    By trippknightly@hotmail.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-01-2005, 11:06 PM

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