+ Reply to Thread
Results 1 to 3 of 3

Automatically run macro that hides cells based on value when target cell changes

  1. #1
    Registered User
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    1

    Automatically run macro that hides cells based on value when target cell changes

    Afternoon!

    Hoping someone can stop me banging my head on my desk.

    I have a spreadsheet that is acting as a project/process tracker where users are required to provide a weekly update. There are 52 cells populated with the week commencing date for these updates to be provided. To make the spreadsheet easier to read I have decided to only show 3 cells at a time, last week, this week and next week. This is populated in the cells below the dates and is calculated using a nested IF statement based on a target cell to be popluated by the user (i.e. if the date entered by the user equals one of the dates in the 52 columns then it is populated with 'This week' and so on). All cells outside of this range are populated with 'Hide'

    I have a simple piece of VBA that does the job but relies on manually running the macro and would like to change the hidden columns when the target cell changes. I've tried additing worksheet_change (byVal target as rnage) and then target.address = but this never seems to work. Also tried application.enableevent = false/true etc... but again no joy

    VBA is as follows

    Sub DisplayDates()

    Application.ScreenUpdating = False

    Dim cell As Range
    For Each cell In Range("i2:br2")
    If cell.Value = "Hide" Then
    cell.EntireColumn.Hidden = True
    End If
    Next
    End Sub

    Anyone that can automate this based on a change in the target cell (which is currently D1) would be a life saver, well not literally but I would greatly appreciate the help.

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Automatically run macro that hides cells based on value when target cell changes

    Welcome to the forum.

    We'd like to help you but first..

    Pls take some minutes to read forum rules and specially-in this case- rule#3 and add code tags around your code.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Forum Contributor
    Join Date
    10-01-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: Automatically run macro that hides cells based on value when target cell changes

    Also a sample spreadsheet will help us understand your demands

+ 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. Need a Macro that Hides Columns Based on Dates compared to Now()
    By yassiada in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2013, 08:29 PM
  2. VBA that hides columns based on dates to and from in selected cells
    By dmcdonough55032 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-21-2012, 06:40 PM
  3. [SOLVED] Macro the hides entire rows based on a drop down list
    By MGK086 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2012, 11:32 AM
  4. Macro to replace cells value automatically based on another cell change event
    By phsilverhp in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-09-2011, 04:36 AM
  5. How do I write a macro that hides a row based on data in Excel?
    By JJO in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-25-2005, 09:06 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