+ Reply to Thread
Results 1 to 5 of 5

Hiding Rows Using If Then and If Then Else Statements - Help!

  1. #1
    Registered User
    Join Date
    01-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    4

    Hiding Rows Using If Then and If Then Else Statements - Help!

    Hello,

    I have a spreadsheet that I have successfully used VBA to hide rows based on certain criteria in the past. The top two if then statements worked fine. I tried to add the IfElse statement and now, none of it works. Any ideas? Thanks!

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("C4").Value = "Tacoma Office" Then
    Rows("34:35").Hidden = False
    Else
    Rows("34:35").Hidden = True

    End If

    If Range("C4").Value = "Tacoma" Then
    Rows("36:40").Hidden = True
    Else
    Rows("36:40").Hidden = False
    End If

    If Range("C4").Value = "Tacoma Office" Then
    Rows("61:65").Hidden = True
    ElseIf Range("C4").Value = "Spokane Office" Or Range("C4").Value = "Boise Office" Or Range("C4").Value = "Walla Walla Office" Then
    Rows("60, 62:65").Hidden = True
    ElseIf Range("C4").Value = "Federal Way Office" Then
    Rows("60:61, 63:65").Hidden = True
    ElseIf Range("C4").Value = "Seattle Office" Then
    Rows("60:62, 64:65").Hidden = True
    ElseIf Range("C4").Value = "Portland Office" Or Range("C4").Value = "Eugene Office" Then
    Rows("60:63, 65").Hidden = True
    ElseIf Range("C4").Value = "Anchorage Office" Or Range("C4").Value = "Juneau Office" Then
    Rows("60:64").Hidden = True
    Else
    Rows("61.65").Hidden = False
    End If
    End Sub


    THANKS!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Hiding Rows Using If Then and If Then Else Statements - Help!

    Try something like this...

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Hiding Rows Using If Then and If Then Else Statements - Help!

    Thanks! It mostly worked! My only question is that at the top, I want rows 36-40 Hidden for Tacoma and not Hidden for the rest and this is doing the opposite. What word do I use to replace the "Not" in this line: Rows("36:40").Hidden = Not Target.Value = "Tacoma"??

    I will see if I can find the answer via google as well. Thanks again! I really appreciate your help!!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Hiding Rows Using If Then and If Then Else Statements - Help!

    The opposite of Not is to remove the word Not.

  5. #5
    Registered User
    Join Date
    01-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Hiding Rows Using If Then and If Then Else Statements - Help!

    I figured it out! 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