+ Reply to Thread
Results 1 to 9 of 9

Build a Dynamic Named Range from criteria.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-13-2009
    Location
    Indiana
    MS-Off Ver
    Excel 2015
    Posts
    183

    Build a Dynamic Named Range from criteria.

    Hello Forum.

    I have some raw data, and in that data are 2 columns. They are Manager and Role. I am trying to create 2 lists, that correspond to their role. I can create a dynamic named range from the column no problem using this formula:
    Formula: copy to clipboard
    =OFFSET($A$1,0,0,MATCH("*",$A:$A,-1),1)


    Now, what I need to be able to do is, add a criteria option to the formula. So build the list off of column B, but only if their role (in column C) is Perm, or Temp.

    Please see the attached spreadsheet.
    Attached Files Attached Files

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Build a Dynamic Named Range from criteria.

    Please see the attached. It uses an event driven macro to repopulate the lists every time there is a change to a cell in columns 1-3.
    Attached Files Attached Files
    Martin

  3. #3
    Forum Contributor
    Join Date
    02-13-2009
    Location
    Indiana
    MS-Off Ver
    Excel 2015
    Posts
    183

    Re: Build a Dynamic Named Range from criteria.

    Thank you for the quick reply. I see that your macro works in the example that I provided, but I would have no idea how to convert that to my workbook. Could you maybe add comments to the macro that would allow me to understand it, and adapt it for use in my workbook.

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Build a Dynamic Named Range from criteria.

    Comments included.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range
    Application.EnableEvents = False 'turns off events so that later lines in the code do not trigger events themselves
    For Each Cell In Target  ' As the target range may have more than one cell in it, each cell is treated individually
        If Cell.Column <= 3 Then 'Checks if the change was made in one of the first three columns - only excutes if it is.
            Range(Cells(2, 6), Cells(Rows.Count, 8)).Clear 'Clears the range below the headers in columns 6 - 8
            For N = 2 To Cells(Rows.Count, 1).End(xlUp).Row 'processes each row in columns 1 - 3 individually
                Cells(Rows.Count, Range(Cells(1, 6), Cells(1, 8)).Find(Cells(N, 3), , xlValues, xlWhole).Column).End(xlUp).Offset(1, 0) = Cells(N, 1) 'looks at the value in column 3 and finds the column header in row 1 which corresponds. Adds the value in column 1 to the next empty cell in the target column.
            Next N
        End If
    Next Cell
    Application.EnableEvents = True 'turns on events again
    End Sub

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Build a Dynamic Named Range from criteria.

    Other approach

    With an pivot table.
    Attached Files Attached Files
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  6. #6
    Forum Contributor
    Join Date
    02-13-2009
    Location
    Indiana
    MS-Off Ver
    Excel 2015
    Posts
    183

    Re: Build a Dynamic Named Range from criteria.

    I have thought about a pivot table approach, but I wanted to stay way from them

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Build a Dynamic Named Range from criteria.

    First => I don't see in your question, you want to stay away from pivot table.

    Second => what's the problem working with pivot table?

    In my example you have a dynamic table, which will be used for pivot table.

    You only have to refresh the pivot table after adding / changing data.

  8. #8
    Forum Contributor
    Join Date
    02-13-2009
    Location
    Indiana
    MS-Off Ver
    Excel 2015
    Posts
    183

    Re: Build a Dynamic Named Range from criteria.

    I apologize that I didn't specify that I wanted to stay away from a pivot table. The reason is this; There is a specific area of the report that this list of Managers needs to go, and a pivot table would change the cells around in such a way that it would mess up the formatting of the report. Also, I am designing this report, but I will not be maintaing it, so I wanted to make it as simple as possible, and something as little as refreshing the table could cause problems.

  9. #9
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Build a Dynamic Named Range from criteria.

    Thanks for responding and explaining.

+ 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