+ Reply to Thread
Results 1 to 4 of 4

Drop down with worksheet_change

Hybrid View

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Drop down with worksheet_change

    So I am trying to use the answer to a drop down to hide a range of rows if a certain answer is selected. Here is the code Ive pieced together but it may not be right at all.. Help please?


    Private Sub Worksheet_Change(ByVal Target As range)
     Dim what, whatrange, hold1, hold2, act, quotetype
     Dim laboronly As String
     
        hold1 = Worksheets(".").[G18].Value   ' First row of range
        hold2 = Worksheets(".").[G19].Value   ' Last row of range
        act = "A" & (hold1 - 3)
        what = hold1 & ":" & hold2
        quotetype = Worksheets("L&M").[E11].Value  'Cell with dropdown list
        laboronly = "Labor ONLY"     'Value of dropdown that will cause above range to hide
        If quotetype = laboronly Then
            range(what).EntireRow.Hidden = True
        ElseIf quotetype <> laboronly Then
            range(what).EntireRow.Hidden = False
        End If
    End Sub

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Drop down with worksheet_change

    jwagman1,

    This code goes in the "L&M" sheet code module:
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Dim lFirstRow As Long
        Dim lLastRow As Long
        
        If Target.Address = "$E$11" Then
            lFirstRow = Int(Sheets(".").Range("G18").Value2)
            lLastRow = Int(Sheets(".").Range("G19").Value2)
            
            'If the rows to hide are on sheet "." then change the Sheets() name
            Sheets("L&M").Rows(lFirstRow & ":" & lLastRow).Hidden = (Target.Value = "Labor ONLY")
        End If
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    08-01-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Drop down with worksheet_change

    Works like a charm!! Thanks much for the help. You rock!

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Drop down with worksheet_change

    You're very welcome

    If that takes of your need, please mark this thread as solved.
    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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