How to Search Through Columns and Display Multiple Instances of Specific Value in a Row

gregwadz

New Member
Joined
Jun 25, 2016
Messages
14
So I have Sheet 1 which contains Client Name (Column A), Date 1 (Column B), Date 2 (Column C).

I then have Sheet 2 which contains individual dates in each cell under row A (A1 - 1/1/2017, A2 - 1/2/2017, A3 - 1/3/2017, etc).

I need a formula that searches through columns B and C on Sheet 1 and displays all Client Names that meet the specific date in the specified row. So if the client has the date 1/1/17, I want their name to display under row 1. I want ALL the clients that meet that specific date to display in the row.

I have included some sample tables to help explain what I'm trying to accomplish.

Sheet 1
ClientDate 1Date 2
Bob Smith1/1/20171/3/2017
Bill Jones1/2/20171/3/2017
Jane Johnson1/1/20171/4/2017
Jack Daniels1/1/20171/2/2017

<tbody>
</tbody>

Sheet 2
DateClient 1Client 2Client 3Client 4
1/1/2017Bob SmithJane JohnsonJack Daniels
1/2/2017
Bill JonesJack Daniels
1/3/2017
Bob SmithBill Jones
1/4/2017Jane Johnson

<tbody>
</tbody>


The order of the clients does not matter, but I would like columns B-K available for up to 10 clients to be inserted under one date. I tried to use a LOOKUP function but I would not be able to display multiple clients. I have a somewhat limited knowledge of Excel. Any help is appreciated. Thank you!
 
Getting an error on Line 9:

For Each Dn In Rng2: Dic.Add (Dn.Value), Array(Dn, 0): Next

Error reads:

Run-time error '457': The key is already associated with an element of this collection.
 
Last edited:
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I think this is because you have duplicate dates in sheet2 col "A".
I'm not sure if you intended to have duplicate dates , it can be overcome ,but you will then have either duplicate return values or one of the duplicates will not have any values.
I'm also not sure why your data and results do not match date/person wise????
 
Upvote 0
Hi Mick, the reason the results were not matching is because I forgot to include the header in the sample spreadsheet. I also had to modify the original code a little bit. Instead of:

For Each Dn In Rng
If Not Dic.exists(Dn.Value) Then
Dic.Add Dn.Value, .Cells(Dn.Row - 1, 1)
Else
Dic(Dn.Value) = Dic(Dn.Value) & "," & .Cells(Dn.Row - 1, 1)

I just simply removed the '- 1' and the data outputs the correct names and dates.

As for the second the macro, you were correct that the error was coming from having duplicate dates in "Sheet2" column A. I removed the extra dates and the macro runs without an error, but the macro doesn't do anything. Nothing changes on sheet 1 or 2 after running the second macro.

Cheers
 
Upvote 0
Thanks for the reply, Mick. I see that your example includes all of the dates in calendar format, but how do I get that to my spreadsheet? Do I transfer all of my data from my spreadsheet to the 'Greg' file? My working spreadsheet is a bit more complicated then I have shown you and I think transferring my data to that file will mess up the macros you're using.

If there's no better way around getting the calendar view, I may just manually sort the dates in sheet 2. It won't be exactly a calendar, but it will show which appointments are upcoming in chronological order.

Really appreciate the help you've given.
 
Upvote 0
It depend how and where you want to run the code:-
You can run it from a button or from when you change a value or select a sheet , if you let me know I'll give you details of how to achieve it.
 
Last edited:
Upvote 0
A button as you have on the example file would be great.

So just so I am clear... I would input all of the dates in Sheet1, then run the original macro which will output all the dates/names onto Sheet2, and then I would press the button and it would format it onto the calendar?

Also would this calendar be able to change over time? Say after a year, will the calendar continue onto the next year and so on?
 
Upvote 0
You're lost me a bit now!!!
My assumption (based on your latest requirement) was that your sheet 1 was as per My sheet1 in file "Greg", the code as per file "Greg" was run and the dates in sheet2 where updated with sheet1 names.

NB:- The original macro is not needed because it gave a list of names with dates rather that updating a list of dates with related names.
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top