Need help with a macro please!

LuBurt

New Member
Joined
Apr 22, 2024
Messages
8
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi,
Can someone please help me, I have some data that needs copying to a new workbook, and there's a lot. I will provide screen shots of examples of what I need to do!

I have one workbook, that shows a list of all customers. There are in total, 744 rows in this workbook, meaning 744 customers.
I have another workbook, that shows all items and the price of that item.
For every customer, I need to copy all items and prices for those items alongside the customers internal ID to a new workbook.
Essentially, this means copying an internal ID from one customer pasting it into a new workbook, copying all items and pricing from another workbook and copying that in to the new workbook. This means I will have to do this for every, single, customer. 744 times.

Here is an example of what I mean.
Copy one customer internal ID. For this example, internal ID 355693.
1713781323968.png

Paste this to a new workbook.
1713781397035.png


Then, copy all item names and unit prices for those items.

1713781489121.png


paste to new workbook alongside internal ID.

1713781545980.png




Autofill internal ID.
1713781580603.png


This needs to be done for every single customers internal id we have, so 744 times!

Is there ANYTHING I can do to make this faster/automated?

Thanks!
 

Attachments

  • 1713781375017.png
    1713781375017.png
    2.1 KB · Views: 2
  • 1713781391395.png
    1713781391395.png
    2.1 KB · Views: 2
  • 1713781450286.png
    1713781450286.png
    16.8 KB · Views: 2

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Is one customer = 1 new workbook? So 744 workbooks?
 
Upvote 0
no all on the same workbook, so approx 25,000 rows in one single workbook
 
Upvote 0
Are the item names and unit price same for all customer?
 
Upvote 0
Are the item names and unit price same for all customer?
yes, all prices and item names are exactly the same, the only changing factor is the internal id which is tied to a customer
 
Upvote 0
Do you prefer a VBA or formula solution?
 
Upvote 0
you have a client workbook
you have a supply workbook
and the Generate Client workbook , paste the code into a module this workbook.

in Generate Client workbook
cell B1 = path to the client workbook file ie: c:\documents\clients.xlsx
cell B2 = path to the supply workbook file
cell B3 = path to the results folder: c:\documents\


run: MakeAllClientLists

it will generate results in folder: B3

Code:
Sub MakeAllClientLists()
Dim wbCLI As Workbook, wbSUPP As Workbook, wbTARG As Workbook
Dim vDir, vClient, vFileCLI, vFileSUPP, vFileTARG
Dim iRows As Integer, i As Integer

vFileCLI = Range("B1").Value    'clients
vFileSUPP = Range("B2").Value   'supplies
vDir = Range("B3").Value        'TARGET FOLDER
vFileTARG = vDir & "results.xlsx"

Workbooks.Open vFileCLI
Set wbCLI = ActiveWorkbook

Workbooks.Open vFileSUPP
Set wbSUPP = ActiveWorkbook
Range("A1").Select
iRows = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.UsedRange.Select

'results
Workbooks.Add
Set wbTARG = ActiveWorkbook
wbTARG.SaveAs vFileTARG

'scan the client list
wbCLI.Activate
Range("A2").Select
While ActiveCell.Value <> ""
  vClient = ActiveCell.Value

  wbTARG.Activate
  Sheets.Add
  Range("B1").Select
  
  wbSUPP.Activate
  Selection.Copy
  
  wbTARG.Activate
  Range("B1").Select
  ActiveSheet.Paste
  
  Range("A2").Select
  For i = 1 To iRows
     Range("A1").Offset(i, 0).Value = vClient
  Next

  ActiveSheet.Name = vClient
  wbTARG.Save
  
   'next client
  wbCLI.Activate
  ActiveCell.Offset(1, 0).Select 'next row
Wend
'free memory
Set wbCLI = Nothing
Set wbSUPP = Nothing
Set wbTARG = Nothing
End Sub
 
Upvote 0
Try this. Replace your cell references at the top.
Book3
ABCDEFGHIJ
1IDCustomerItem NamePriceNumber1Part 110
2Number1A4Part 110Number1Part 215
3Number2B4Part 215Number1Part 320
4Number3C4Part 320Number1Part 425
5Part 425Number2Part 110
6Number2Part 215
7Number2Part 320
8Number2Part 425
9Number3Part 110
10Number3Part 215
11Number3Part 320
12Number3Part 425
Sheet6
Cell Formulas
RangeFormula
H1:J12H1=LET(a,A2:A4,b,D2:D5,d,D2:E5, ID,VSTACK(a,""), s,VSTACK(0,SEQUENCE(ROWS(a),,ROWS(b),0)), sc,SCAN(1,s,LAMBDA(a,b,a+b)), x,XLOOKUP(SEQUENCE(SUM(ROWS(a)*(ROWS(b)))),sc,ID,,-1), m,TOCOL(MAKEARRAY(ROWS(a),ROWS(b)*2,LAMBDA(r,c, INDEX(TOROW(d),1,c)))), h,HSTACK(x,WRAPROWS(m,2)),h)
Dynamic array formulas.
 
Upvote 0
This is more concise.
Excel Formula:
=LET(
s,ROUNDUP(SEQUENCE(ROWS(A2:A5)*ROWS(D2:D5))/ROWS(D2:D5),0),
ID,INDEX(A2:A5,s),
Item, INDEX(D2:D5,s),
price, INDEX(E2:E5,s),
HSTACK(ID,Item,price))
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

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