+ Reply to Thread
Results 1 to 8 of 8

If/Then Formula - Hide or Unhide Rows

  1. #1
    Registered User
    Join Date
    02-29-2012
    Location
    Nevada, USA
    MS-Off Ver
    Excel 2010
    Posts
    6

    If/Then Formula - Hide or Unhide Rows

    Hi:
    I looked up a few examples in this forum, but I am a beginner and I need your help. I have a drop down window with choices Yes, No. I have pointed that to cell J18 with a formula that says, if it's Yes, then = 0, if No, then =1. Now I need a VBA to hide rows 19 and 20 if cell J18 = 1, Unhide of = 0. Can someone help me?

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: If/Then Formula - Hide or Unhide Rows

    Put this in your worksheet module

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-29-2012
    Location
    Nevada, USA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: If/Then Formula - Hide or Unhide Rows

    You are the best!! Thank you so much!!

  4. #4
    Registered User
    Join Date
    02-29-2012
    Location
    Nevada, USA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: If/Then Formula - Hide or Unhide Rows

    If I want to do another code within the same worksheet for cell J21, if J21 = 1 then hide row 22, if zero, then unhide. Can that be done within the same VBA?
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    On Error GoTo ExitSub
    Select Case Range("J18")
    Case 1
    Rows("19:20").Hidden = True
    Case 0
    Rows("19:20").Hidden = False
    Case Else
    'Do Nothing
    End Select

    ExitSub:
    End Sub

    Private Sub Worksheet_SelectionChange2(ByVal Target As Range)

    On Error GoTo ExitSub
    Select Case Range("J21")
    Case 1
    Row("22").Hidden = True
    Case 0
    Row("22").Hidden = False
    Case Else
    'Do Nothing
    End Select

    ExitSub:
    End Sub


    Or am I completely off??

    Thanks, again

  5. #5
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: If/Then Formula - Hide or Unhide Rows

    That's looks right to me. You might want to tag your code just an FYI. You can always test it out on your own.

  6. #6
    Registered User
    Join Date
    02-29-2012
    Location
    Nevada, USA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: If/Then Formula - Hide or Unhide Rows

    It didn't work so I thought I was doing something wrong....

  7. #7
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: If/Then Formula - Hide or Unhide Rows

    You have to put those 2 procedures within the same procedures. PS:Rows not Row. Just an FYI.

    Actually put the code in Worksheet_Change module otherwise it is going to update every time you select a cell

    Please Login or Register  to view this content.
    Last edited by JieJenn; 02-29-2012 at 03:48 PM.

  8. #8
    Registered User
    Join Date
    02-29-2012
    Location
    Nevada, USA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: If/Then Formula - Hide or Unhide Rows

    Got it to work with changing the Row to Rows, for the second event! Thank you so much!!

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    On Error GoTo ExitSub
    Select Case Range("J18")
    Case 1
    Rows("19:20").Hidden = True
    Case 0
    Rows("19:20").Hidden = False
    Case Else
    'Do Nothing
    End Select

    On Error GoTo ExitSub
    Select Case Range("J21")
    Case 1
    Rows("22:22").Hidden = True
    Case 0
    Rows("22:22").Hidden = False
    Case Else
    'Do Nothing
    End Select

    ExitSub:
    End Sub

+ 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