+ Reply to Thread
Results 1 to 3 of 3

Hide Rows based on cell values

Hybrid View

  1. #1
    Registered User
    Join Date
    08-22-2011
    Location
    Manchester
    MS-Off Ver
    Excel 2003
    Posts
    3

    Hide Rows based on cell values

    Hi All,

    I think i am making this problem complicated and Im pulling my hair out.

    I have two values in cells:

    A1 = 9
    A2 = 15

    I am trying to then get excel to hide rows based on these values but I cant get it to work..

    Ive tried:
    var1 = range("a1").value
    var2 = range("a2").value
    activesheet.rows(var1 : var2).hidden = True

    But this will not compile "Expected: list seperator or )".

    I also want to then set the printarea to "A" var1: "D" var2 (ie. A9:D15 in this case.)

    Im stuck can someone point me in the right direction please?

    Thanks.
    Last edited by Chinny123; 08-23-2011 at 08:46 AM.

  2. #2
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544

    Re: Hide Rows based on cell values

    Try

    var1 ="a1"
    var2 = "a2"
    activesheet.rows(var1 & ":" & var2).hidden = True
    or more simple

    activesheet.rows("A1:A2").hidden = True
    Just keep it simple !


    http://www.excelguide.eu
    In English as well as in Dutch

  3. #3
    Registered User
    Join Date
    08-22-2011
    Location
    Manchester
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Hide Rows based on cell values

    Thanks for the nudge in the right direction.

    Var1 = Range("A1").Value
    Var2 = Range("A2").Value
    
    If ActiveSheet.Rows(Var1 & ":" & Var1).Hidden = True Then
        ActiveSheet.Rows(Var1 & ":" & Var2).Hidden = False
    Else
        ActiveSheet.Rows(Var1 & ":" & Var2).Hidden = True
    End If
    Works a charm for the hiding and

    PrintRange = "A" & Var3 & ":" & "D" & Var2
        ActiveSheet.PageSetup.PrintArea = PrintRange
    for setting the print range.

    Thanks!

+ 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