+ Reply to Thread
Results 1 to 3 of 3

I am trying to Hide Columns based on a drop down list answer if it appears on any row

  1. #1
    Registered User
    Join Date
    06-20-2013
    Location
    NJ
    MS-Off Ver
    Excel 2003
    Posts
    2

    I am trying to Hide Columns based on a drop down list answer if it appears on any row

    Is it possible to Hide columns based on the values from a drop down list in individual rows. For example, I am creating a report that has descriptions of expenses and if "Mileage" is selected from a drop down list, then columns h through k should be visible and if any other type of expense is selected, then those columns should be hidden. This is an example of the code I wrote where the macro works on cell D11, but I am looking for this macro to work with a range of D11:D:32 if possible where if the word Mileage is included if even just once, then those columns can be included in the worksheet:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("d11") = "Mileage" Then
    Columns("h:k").Select
    Selection.EntireColumn.Hidden = False
    Range("d11").Select
    Else
    Columns("h:k").Select
    Selection.EntireColumn.Hidden = True
    End If

    End Sub

    Please advise

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: I am trying to Hide Columns based on a drop down list answer if it appears on any row

    Hi arugg321,
    welcome!
    try this
    Please Login or Register  to view this content.
    nb
    next time when you post a code, please read the forum rules to know "how to"
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  3. #3
    Registered User
    Join Date
    06-20-2013
    Location
    NJ
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: I am trying to Hide Columns based on a drop down list answer if it appears on any row

    Thank you John, that is very close to what I am looking for, the initial code that I included was flawed in that I was only limited to the last cell that included the range which in my case was one individual cell. The only issue that I am now having is that lets say I select "Mileage" in Cell "D11", the columns would be visible which is what I want but then lets say I selected "Airfare" in Cell "D12", the columns that I wanted to appear when "Mileage" was selected are now hidden again. Is there a way to have this sheet set up so that if the word "Mileage" is selected those columns will be visible regardless of what is in the rest of the range, and if "Mileage" is not selected at all then those columns remain hidden?

    Thanks for your help so far!

+ 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