How do I write this loop?

Agent86

Board Regular
Joined
Feb 28, 2003
Messages
229
I've been working on this one for about an hour now, but just can't figure out how to write the correct type of loop.

I have a list of names beginning in cell E20. This list will continue to expand and repeats many of the names. Beginning in cell F20 I have a second list of names that will continue to expand as well. All names in Column F are associated with the name on the same row in Column E.

I'd like to enter a name (from the list in Column E) in cell B5 and generate a new list which would begin in cell C5. This new list should be all the names from Column F whose cooresponding name in Column E matches what was entered in B5.

... I'm sorry if all that sounds confusing. Please let me know if clarification is needed. Thank you in advance fro any guidance you may be able to provide.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi there

You might like to try this:


Range("E20", Range("E65536").End(xlUp)).Select
For Each cell In Range("E20", Range("E65536").End(xlUp))
If cell.Value = Range("B5").Value Then
Range("C65536").End(xlUp).Offset(1, 0).Value = cell.Offset(0, 1).Value
End If
Next
End Sub

Note: You must have an entry in C4 before you start.
If the corresponding cell in column F is blank it will not show

regards
Derek

ps You can remove the first line of code. It was just to prove it was selecting expanding data.
 
Upvote 0
Use an advanced filter (Data | Filter > Advanced Filter...) or create a PivotTable. If you go with the latter, put both column E and column F as row fields, and don't specify any data field.
Agent86 said:
I've been working on this one for about an hour now, but just can't figure out how to write the correct type of loop.

I have a list of names beginning in cell E20. This list will continue to expand and repeats many of the names. Beginning in cell F20 I have a second list of names that will continue to expand as well. All names in Column F are associated with the name on the same row in Column E.

I'd like to enter a name (from the list in Column E) in cell B5 and generate a new list which would begin in cell C5. This new list should be all the names from Column F whose cooresponding name in Column E matches what was entered in B5.

... I'm sorry if all that sounds confusing. Please let me know if clarification is needed. Thank you in advance fro any guidance you may be able to provide.
 
Upvote 0
Thank you both!

Derek, your method works fine. I was not approaching it correctly. I was trying to write a code that would insert a VLOOKUP formula and loop it.

tusharm, I thought about using a filter, but didn't want the name from column E to be listed on every line of the report. I never thought about a pivot table. I've not used those much, but I think that I'll explore your suggestion to see how that works.

Thank you again for your assistance.
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,306
Members
448,564
Latest member
ED38

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