+ Reply to Thread
Results 1 to 5 of 5

Hide rows and columns based on a combobox value

Hybrid View

  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    3

    Hide rows and columns based on a combobox value

    I want to hide rows and columns based on cell J5, if j5=5 then hide rows 14-18 from columnc-L,.
    I am new to VBA and aprecaite your help
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,080

    Re: Hide rows and columns based on a combobox value

    Try:

    Sub Test()
        If Range("J5") = 5 Then
            Rows("14:18").Hidden = True
            Columns("C:L").Hidden = True
        End If
    End Sub

  3. #3
    Registered User
    Join Date
    11-05-2012
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Hide rows and columns based on a combobox value

    What I meant is if J5= i, then show rows from 14 to 14+i and hide the rest.
    i=1,10
    regards

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,080

    Re: Hide rows and columns based on a combobox value

    Does this work?

    Sub Test()
        Dim x As Integer
        x = Range("J5").Value
        Dim i As Integer
        Dim bottomB As Integer
        bottomB = Range("B" & Rows.Count).End(xlUp).Row
        On Error Resume Next
        For i = bottomB To 1 Step -1
            If Rows(i).Row < 14 Or Rows(i).Row > 14 + x Then
                Rows(i).Hidden = True
            End If
        Next i
            Columns("C:L").Hidden = True
    End Sub
    Last edited by Mumps1; 11-23-2012 at 03:41 PM.

  5. #5
    Registered User
    Join Date
    11-05-2012
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Hide rows and columns based on a combobox value

    Thanks a lot, done

+ 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