Loop through Range

johnbird1988

Board Regular
Joined
Oct 6, 2009
Messages
199
Hello

I am after some best approach advice. I have a list of transaction data in Sheet1 and a list of customers in Sheet2. I would like to return in 4 individual columns in Sheet2 next the the customer ID the four latest transactions.

Which is the best approach than doing two loops. Is there a way I can achieve this using one loop through the data in Sheet1. I was possibly think about adding the Customer IDs to a collection but them I was not sure about how to write the collection back into Sheet2.

Open to options and Ideas to do this in the most efficient way.

Thank you

John
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Is VBA required?

I made this formula with:

Sheet 1
Customer IDs in column A, transaction numbers in column B

Sheet 2
Customer IDs in column A, most recent transactions in columns B to E (most recent to 4th most respectively).

Sheet 2 cell B2 =INDEX(Sheet1!$B$2:$B$28,LARGE(IF(Sheet1!$A$2:$A$28=$A2,ROW(Sheet1!$A$2:$A$28)-MIN(ROW(Sheet1!$A$2:$A$28))+1),COLUMNS($B2:B2)))

Confirmed with CTL+SHIFT+ENTER then copied accross and down as needed.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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