Macro to paste data to new tab based on changes in ID

SereneMal

New Member
Joined
Jan 17, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello all, hoping someone can help me out. I have a report that I download with client account numbers as an identifier and several fields that are associated with that ID. I would like to build a macro that will cut/copy and paste all the rows that have the same account number into a new tab.
Columns: fixed number of columns, with consistent header
Rows: the number of rows associated with each unique account #/ID constantly changes.
Unique IDs: variable or fixed @ 10 if needed*
*The tabs can be pre-created blank or with the header and named e.g. Acct 1, Acct 2... Acct 10.
Let me know if any more specifics would be of assistances.
Thanks for looking!

Sample Output.xlsm
ABC
1Account NumberProductQuantity
2Acct #1Oranges2
3Acct #1Cherries5
4Acct #1Limes4
5Acct #2Cherries12
6Acct #2Broccoli1.50%
7Acct #3Salad1000
8Acct #3Cherries50
9Acct #3Oranges25
10Acct #3Melons66
11Acct #3Figs7
12Acct #4Limes-2
13Acct #4Salad5.50%
Sample Output



Sample Output.xlsm
ABC
1Account NumberProductQuantity
2Acct #1Oranges2
3Acct #1Cherries5
4Acct #1Limes4
5
6
Acct 1


Sample Output.xlsm
ABC
1Account NumberProductQuantity
2Acct #2Cherries12
3Acct #2Broccoli1.50%
4
5
Acct 2
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Welcome to the Board!

Since you have the newest version of Excel (365), the easiest way would probably be just to have the one sheet with ALL the data (like you show), and then just use the new FILTER function on each of the individual pages that follow. That will dynamically pull all the matching data from your front sheet. And the best news is that you may be able to do all of this without any VBA, if you know how many different accounts you are dealing with (so you can set up a tab for each).

See: FILTER Function
 
Upvote 0
Solution
That is awesome, thanks!
Had to create a slight work around since the identifiers ("include" argument in FILTER) is constantly changing. Essentially, I added a new "Identifier" tab and use UNIQUE to create the list of identifiers. Then I set "include" = those identifiers, #1-10.... so 10 tabs.
Happy times!
 
Upvote 0
You are welcome. Glad I was able to help.

Yeah, that new function is really cool! I really like how it dynamically adds the right number of rows and columns, depending on your data.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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