+ Reply to Thread
Results 1 to 6 of 6

Need help trying to hide rows based on a checkbox in excel

Hybrid View

  1. #1
    Registered User
    Join Date
    04-05-2013
    Location
    Harrison, NJ
    MS-Off Ver
    Excel 2007
    Posts
    3

    Need help trying to hide rows based on a checkbox in excel

    Hi,

    I have written some code in order to hide rows based on a checkbox. Initially I wrote the code to hide rows based on a value in a cell and it worked fine, however when i moved to a checkbox it did not work. I have pasted part of the code below.

    Private Sub Worksheet_change(ByVal Target As Range)
    ActiveSheet.Activate
    
    If Not Application.Intersect(Range("A18"), Range(Target.Address)) Is Nothing Then
        Select Case Target.Value
        Case Is = "TRUE":  Rows("39:47").EntireRow.Hidden = False
                       ' Rows("39:47").EntireRow.Hidden = True
        End Select
      End If
    
    If Not Application.Intersect(Range("A19"), Range(Target.Address)) Is Nothing Then
       Select Case Target.Value
       Case Is = "TRUE":   Rows("49:57").EntireRow.Hidden = False
                       ' Rows("59:67").EntireRow.Hidden = True
        
       End Select
      End If
    Also the hide and unhide of rows never worked properly can someone please help.
    Last edited by jeffreybrown; 03-26-2020 at 02:20 PM. Reason: Please use code tags!

  2. #2
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Need help trying to hide rows based on a checkbox in excel

    Hi,
    I think you can have better results when you use instead:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Cheers
    Erwin
    I started learning VBA because I was lazy ...
    Still developing.... being more lazy...

  3. #3
    Registered User
    Join Date
    04-05-2013
    Location
    Harrison, NJ
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Need help trying to hide rows based on a checkbox in excel

    Quote Originally Posted by Eastw00d View Post
    Hi,
    I think you can have better results when you use instead:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Cheers
    Erwin
    Thanks so much I will try what you suggest and see how it works out.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,719

    Re: Need help trying to hide rows based on a checkbox in excel

    Hi & welcome to the board.
    Rather than checkboxes, which don't trigger a change event, why not just put an X in the cell instead?

  5. #5
    Registered User
    Join Date
    04-05-2013
    Location
    Harrison, NJ
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Need help trying to hide rows based on a checkbox in excel

    I tried using X as the trigger in a cell based on the checkbox =TRUE/FALSE and got mixed results. I think I need to work on a better VBA code.

  6. #6
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Need help trying to hide rows based on a checkbox in excel

    Maybe this is what you are looking for:
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    
    If Not Application.Intersect(Range("A18"), Range(Target.Address)) Is Nothing Then
        Select Case LCase(Target.Value)
        Case Is = "x"
            Rows("39:47").EntireRow.Hidden = False
         Case Is <> "x"
            Rows("39:47").EntireRow.Hidden = True
        End Select
      End If
    End Sub
    Cheers
    Erwin

+ 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. ActiveX Checkbox - Hide rows based on color
    By LSDSCS in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-23-2019, 02:41 PM
  2. Using a Checkbox to Hide Rows based on Cell Value
    By leedjc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2018, 03:45 AM
  3. Userform/checkbox hide/unhide rows based on cell value
    By MOHAMMESALMAN in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-03-2015, 03:17 AM
  4. Hide rows based on userform checkbox
    By rodrignj in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-21-2015, 05:38 AM
  5. [SOLVED] Macro to Automatically Hide/Unhide Rows Based on Checkbox
    By bga10s in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2014, 07:32 PM
  6. Macro cannot hide rows based on cell linked to checkbox
    By fernaldd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2009, 11:46 AM

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