Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Dynamic filtering into a new range

Hi,

I'm doing up a roster spreadsheet and would like a simple way of adding some
dynamic filtering. Here is an example of what I want to do

Input:
Task 1 Task 2 Task 3 Task 4...
Alice y y y
Bob y y
Eve y y y
....


Output:

Available people
Task 1 Alice, Bob, Eve
Task 2 Alice
Task 3 Alice, Eve
Task 4 Bob
....

OR like this (if easier):

Available people
Task 1 Alice Bob Eve
Task 2 Alice
Task 3 Alice Eve
Task 4 Bob

Using array formulas I can get the following:

Available people
Task 1 Alice Bob Eve
Task 2 Alice
Task 3 Alice Eve
Task 4 Bob ...
....

But this means the table gets very wide. Any ideas?

Thanks
Atreides
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Dynamic filtering into a new range

Hi "Atreides"

Assuming your data is in the below format with tasknames in Row1 and names
in ColA starting from Row1; The expected output is given below..Try with the
below data and later uou can adjust to suit..try the below macro and
feedback..

Your data:

ColA ColB ColC ColD ColE
Task 1 Task 2 Task 3 Task 4
Alice y y y
Bob y y
Eve y y y

Expected Output:

Task 1 Alice,Bob,Eve
Task 2 Alice
Task 3 Alice,Bob,Eve
Task 4 Eve

Sub Macro()
Dim arrData As Variant, strTemp As String
Dim lngCol As Long, lngLastCol As Long
Dim lngRow As Long, lngLastRow As Long

lngLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
ReDim arrData(1, lngLastCol - 1)

For lngCol = 2 To lngLastCol
strTemp = ""
For lngRow = 2 To lngLastRow
If Cells(lngRow, lngCol) = "y" Then _
strTemp = strTemp & "," & Range("A" & lngRow)
Next
arrData(0, lngCol - 2) = Cells(1, lngCol)
arrData(1, lngCol - 2) = Mid(strTemp, 2)
Next

Range("A" & lngLastRow + 5).Resize(4, 2) = _
WorksheetFunction.Transpose(arrData)
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Atreides" wrote:

Hi,

I'm doing up a roster spreadsheet and would like a simple way of adding some
dynamic filtering. Here is an example of what I want to do

Input:
Task 1 Task 2 Task 3 Task 4...
Alice y y y
Bob y y
Eve y y y
...


Output:

Available people
Task 1 Alice, Bob, Eve
Task 2 Alice
Task 3 Alice, Eve
Task 4 Bob
...

OR like this (if easier):

Available people
Task 1 Alice Bob Eve
Task 2 Alice
Task 3 Alice Eve
Task 4 Bob

Using array formulas I can get the following:

Available people
Task 1 Alice Bob Eve
Task 2 Alice
Task 3 Alice Eve
Task 4 Bob ...
...

But this means the table gets very wide. Any ideas?

Thanks
Atreides

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Dynamic filtering into a new range

Hi Jacob,

Thanks for taking the time to answer my question and write up that code.
However what I was looking for was a more generic solution that I can use in
the future.

I kept on searching and here's what I found to do the job.

{=STRINGCONCAT(", ",1,IF(Task1Yes="y",Names,""))}

For the benefit of others like me:
- STRINGCONCAT is a great little user-defined function I found by a guy
called Chip Pearson. It actually does what you'd think Excel's CONCATENATE
should do. You can give it a range, array or whatever and specify a separator
(in this case, I've used ", ") and it will concatenate away. There is also an
option for skipping blanks and it knows not to put a separator at the end of
the list. I was so stoked when I found it that I had to share.
- Here, "Task1Yes" and "Names" are defined names for ColB and ColA (as per
Jacob's reply)
- The IF function is applied over the array. So anything that satisfies the
test (="y") will be included in the array and anything that fails will be
left blank.

Again, thanks for your help and time but the thing I like about my solution
is that it's generic. Now that I know about this function, I can use it again
in other situations. I have no doubt that your code would work in this case
but I lack the skills to modify it to use in other situations.

Thanks again
Atreides.



"Jacob Skaria" wrote:

Hi "Atreides"

Assuming your data is in the below format with tasknames in Row1 and names
in ColA starting from Row1; The expected output is given below..Try with the
below data and later uou can adjust to suit..try the below macro and
feedback..

Your data:

ColA ColB ColC ColD ColE
Task 1 Task 2 Task 3 Task 4
Alice y y y
Bob y y
Eve y y y

Expected Output:

Task 1 Alice,Bob,Eve
Task 2 Alice
Task 3 Alice,Bob,Eve
Task 4 Eve

Sub Macro()
Dim arrData As Variant, strTemp As String
Dim lngCol As Long, lngLastCol As Long
Dim lngRow As Long, lngLastRow As Long

lngLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
ReDim arrData(1, lngLastCol - 1)

For lngCol = 2 To lngLastCol
strTemp = ""
For lngRow = 2 To lngLastRow
If Cells(lngRow, lngCol) = "y" Then _
strTemp = strTemp & "," & Range("A" & lngRow)
Next
arrData(0, lngCol - 2) = Cells(1, lngCol)
arrData(1, lngCol - 2) = Mid(strTemp, 2)
Next

Range("A" & lngLastRow + 5).Resize(4, 2) = _
WorksheetFunction.Transpose(arrData)
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Atreides" wrote:

Hi,

I'm doing up a roster spreadsheet and would like a simple way of adding some
dynamic filtering. Here is an example of what I want to do

Input:
Task 1 Task 2 Task 3 Task 4...
Alice y y y
Bob y y
Eve y y y
...


Output:

Available people
Task 1 Alice, Bob, Eve
Task 2 Alice
Task 3 Alice, Eve
Task 4 Bob
...

OR like this (if easier):

Available people
Task 1 Alice Bob Eve
Task 2 Alice
Task 3 Alice Eve
Task 4 Bob

Using array formulas I can get the following:

Available people
Task 1 Alice Bob Eve
Task 2 Alice
Task 3 Alice Eve
Task 4 Bob ...
...

But this means the table gets very wide. Any ideas?

Thanks
Atreides

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Dynamic filtering into a new range

--Thanks for sharing that.

--The macro posted is a generic one. As long as your data range starts from
cell A1 you dont need to modify.

If this post helps click Yes
---------------
Jacob Skaria


"Atreides" wrote:

Hi Jacob,

Thanks for taking the time to answer my question and write up that code.
However what I was looking for was a more generic solution that I can use in
the future.

I kept on searching and here's what I found to do the job.

{=STRINGCONCAT(", ",1,IF(Task1Yes="y",Names,""))}

For the benefit of others like me:
- STRINGCONCAT is a great little user-defined function I found by a guy
called Chip Pearson. It actually does what you'd think Excel's CONCATENATE
should do. You can give it a range, array or whatever and specify a separator
(in this case, I've used ", ") and it will concatenate away. There is also an
option for skipping blanks and it knows not to put a separator at the end of
the list. I was so stoked when I found it that I had to share.
- Here, "Task1Yes" and "Names" are defined names for ColB and ColA (as per
Jacob's reply)
- The IF function is applied over the array. So anything that satisfies the
test (="y") will be included in the array and anything that fails will be
left blank.

Again, thanks for your help and time but the thing I like about my solution
is that it's generic. Now that I know about this function, I can use it again
in other situations. I have no doubt that your code would work in this case
but I lack the skills to modify it to use in other situations.

Thanks again
Atreides.



"Jacob Skaria" wrote:

Hi "Atreides"

Assuming your data is in the below format with tasknames in Row1 and names
in ColA starting from Row1; The expected output is given below..Try with the
below data and later uou can adjust to suit..try the below macro and
feedback..

Your data:

ColA ColB ColC ColD ColE
Task 1 Task 2 Task 3 Task 4
Alice y y y
Bob y y
Eve y y y

Expected Output:

Task 1 Alice,Bob,Eve
Task 2 Alice
Task 3 Alice,Bob,Eve
Task 4 Eve

Sub Macro()
Dim arrData As Variant, strTemp As String
Dim lngCol As Long, lngLastCol As Long
Dim lngRow As Long, lngLastRow As Long

lngLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
ReDim arrData(1, lngLastCol - 1)

For lngCol = 2 To lngLastCol
strTemp = ""
For lngRow = 2 To lngLastRow
If Cells(lngRow, lngCol) = "y" Then _
strTemp = strTemp & "," & Range("A" & lngRow)
Next
arrData(0, lngCol - 2) = Cells(1, lngCol)
arrData(1, lngCol - 2) = Mid(strTemp, 2)
Next

Range("A" & lngLastRow + 5).Resize(4, 2) = _
WorksheetFunction.Transpose(arrData)
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Atreides" wrote:

Hi,

I'm doing up a roster spreadsheet and would like a simple way of adding some
dynamic filtering. Here is an example of what I want to do

Input:
Task 1 Task 2 Task 3 Task 4...
Alice y y y
Bob y y
Eve y y y
...


Output:

Available people
Task 1 Alice, Bob, Eve
Task 2 Alice
Task 3 Alice, Eve
Task 4 Bob
...

OR like this (if easier):

Available people
Task 1 Alice Bob Eve
Task 2 Alice
Task 3 Alice Eve
Task 4 Bob

Using array formulas I can get the following:

Available people
Task 1 Alice Bob Eve
Task 2 Alice
Task 3 Alice Eve
Task 4 Bob ...
...

But this means the table gets very wide. Any ideas?

Thanks
Atreides

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Filtering...Need Help cmeyer Excel Worksheet Functions 0 April 16th 10 04:08 PM
Dynamic Filtering Flintstone[_2_] Excel Discussion (Misc queries) 2 October 29th 09 01:58 PM
dynamic range based on criteria, within a dynamic range, passed to a function [email protected] Excel Programming 5 October 9th 07 10:13 PM
creating a dynamic range based on criteria, within a dynamic range, and passing it to a function [email protected] Excel Programming 0 October 9th 07 05:22 PM
Filtering a dynamic range Basil Excel Worksheet Functions 5 April 30th 07 06:05 PM


All times are GMT +1. The time now is 08:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"