From Dropdown, pull data to a table from another worksheet

Mack23

New Member
Joined
Aug 11, 2021
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hello,

Currently working on a workbook that has inventory allocation on one sheet and another sheet that is going to pull data and make an order sheet for the customer. On the order sheet, I have a table with a dropdown that is selecting the customer. Once a customer is selected, then I would like to be able to fill in the line items from the allocation sheet, on consecutive lines (old sheet had a row per product that used VLOOKUP's to pull the product information) so there are no blank row(s) between each allocated product on the order sheet.

The way I am thinking about making the macro is to first find the customer on the allocation sheet from the selected customer drop down on Order sheet. Second find all the cells with values in the column of that customer in the allocation sheet>copy and pasting into the order sheet on the respect rows. Third would be to make sure there are enough lines on the order sheet before copying a line. I can visualize what the macro will need to do, just have been not successful with the second part or combining all three parts together. any help is appreciated, even if it is part of the solution (inserting rows, finding customer, copying data). I feel like this is very complicated, but the last time I asked for help on this forum the solution wiped my 10 line macro for a 1 line code....

Thank you,
Mack

Allocation Sheet
1629818831902.png


Order Sheet
1629818894745.png
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Mack,

Do you prefer VBA or is formula ok?
 
Upvote 0
Hi Mack,

Do you prefer VBA or is formula ok?
I don't know if a formula will entirely work for what is needed, especially for the case of inserting a row if the table fills up with more than the shown rows.

The old Order sheet used vlookups but it made a "sawtooth" (blank rows) in the table between products that the customer was ordering. Then I did try a INDEX/MATCH type formula, but that was not working any better than the VLOOKUP (just a little cleaner in logic to me).
 
Upvote 0
You could use this? I'm staging the allocation data with named ranges which changes with the drop down.

Expand the ranges as required for your order size, the staging area will still work if hidden.

Pull data from Dropdown.xlsx
ABCDEFGHIJKLM
1CustomerA-1002A-1023A-1020B-0233B-0344B-0259C-0800C-0821C-0843
2Batch # DescriptionSKUTotal
3J20442STEELROD1000200200400200
4H23343STEELTUBE2000200500100250250700
5E33432ALUMINUMTUBE3000600400100250450750100350
6J55032TINROD800100250150300
7J55402TINWIRE800150150200300
8H123405COPPERWIRE1200500700
9E44531COPPERTUBE2700500400250450500600
Allocation


Pull data from Dropdown.xlsx
ABCDEFGHIJKL
1
2CUSTOMERA-1023
3
4Total
5
6Batch # DescriptionSKUQuantityList PriceLine TotalBatch # DescriptionSKUQuantityRows
7J20442STEELROD200J20442STEELROD2001
8H23343STEELTUBE200H23343STEELTUBE2001
9J55032TINROD100E33432ALUMINUMTUBE01
10J55402TINWIRE150J55032TINROD1001
11E44531COPPERTUBE400J55402TINWIRE1501
12H123405COPPERWIRE01
13E44531COPPERTUBE4001
1401
1501
1601
Order
Cell Formulas
RangeFormula
A7A7=IF(ROWS(A$7:A7)>COUNTIF($K$7#,">0"),"",INDEX(Batch,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS(A$7:A7))))
B7B7=IF(ROWS(B$7:B7)>COUNTIF($K$7#,">0"),"",INDEX(Description,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS(B$7:B7))))
C7C7=IF(ROWS(C$7:C7)>COUNTIF($K$7#,">0"),"",INDEX(SKU,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS(C$7:C7))))
D7D7=IF(ROWS($D$7:D7)>COUNTIF($K$7#,">0"),"",INDEX($K$7#,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS($D$7:D7))))
H7:H13H7=Batch
I7:I13I7=Description
J7:J13J7=SKU
K7:K16K7=OFFSET(INDIRECT(CELL("address",INDEX(Allocation!$E$1:$M$1,MATCH($C$2,Allocation!$E$1:$M$1,0)))),2,,COUNT(L:L))
Press CTRL+SHIFT+ENTER to enter array formulas.
Dynamic array formulas.
Named Ranges
NameRefers ToCells
Batch=Allocation!$A$3:INDEX(Allocation!$1:$1000,COUNTA(Allocation!$A:$A)+1,1)A7:C7, H7:J7, H8
Description=Allocation!$B$3:INDEX(Allocation!$1:$1000,COUNTA(Allocation!$B:$B)+1,2)A7:C7, H7:J7, I8
SKU=Allocation!$C$3:INDEX(Allocation!$1:$1000,COUNTA(Allocation!$C:$C)+1,3)A7:C7, H7:J7, J8
Cells with Data Validation
CellAllowCriteria
C2:C4List=Allocation!$E$1:$M$1
 
Upvote 0
Solution
You could use this? I'm staging the allocation data with named ranges which changes with the drop down.

Expand the ranges as required for your order size, the staging area will still work if hidden.

Pull data from Dropdown.xlsx
ABCDEFGHIJKLM
1CustomerA-1002A-1023A-1020B-0233B-0344B-0259C-0800C-0821C-0843
2Batch # DescriptionSKUTotal
3J20442STEELROD1000200200400200
4H23343STEELTUBE2000200500100250250700
5E33432ALUMINUMTUBE3000600400100250450750100350
6J55032TINROD800100250150300
7J55402TINWIRE800150150200300
8H123405COPPERWIRE1200500700
9E44531COPPERTUBE2700500400250450500600
Allocation


Pull data from Dropdown.xlsx
ABCDEFGHIJKL
1
2CUSTOMERA-1023
3
4Total
5
6Batch # DescriptionSKUQuantityList PriceLine TotalBatch # DescriptionSKUQuantityRows
7J20442STEELROD200J20442STEELROD2001
8H23343STEELTUBE200H23343STEELTUBE2001
9J55032TINROD100E33432ALUMINUMTUBE01
10J55402TINWIRE150J55032TINROD1001
11E44531COPPERTUBE400J55402TINWIRE1501
12H123405COPPERWIRE01
13E44531COPPERTUBE4001
1401
1501
1601
Order
Cell Formulas
RangeFormula
A7A7=IF(ROWS(A$7:A7)>COUNTIF($K$7#,">0"),"",INDEX(Batch,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS(A$7:A7))))
B7B7=IF(ROWS(B$7:B7)>COUNTIF($K$7#,">0"),"",INDEX(Description,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS(B$7:B7))))
C7C7=IF(ROWS(C$7:C7)>COUNTIF($K$7#,">0"),"",INDEX(SKU,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS(C$7:C7))))
D7D7=IF(ROWS($D$7:D7)>COUNTIF($K$7#,">0"),"",INDEX($K$7#,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS($D$7:D7))))
H7:H13H7=Batch
I7:I13I7=Description
J7:J13J7=SKU
K7:K16K7=OFFSET(INDIRECT(CELL("address",INDEX(Allocation!$E$1:$M$1,MATCH($C$2,Allocation!$E$1:$M$1,0)))),2,,COUNT(L:L))
Press CTRL+SHIFT+ENTER to enter array formulas.
Dynamic array formulas.
Named Ranges
NameRefers ToCells
Batch=Allocation!$A$3:INDEX(Allocation!$1:$1000,COUNTA(Allocation!$A:$A)+1,1)A7:C7, H7:J7, H8
Description=Allocation!$B$3:INDEX(Allocation!$1:$1000,COUNTA(Allocation!$B:$B)+1,2)A7:C7, H7:J7, I8
SKU=Allocation!$C$3:INDEX(Allocation!$1:$1000,COUNTA(Allocation!$C:$C)+1,3)A7:C7, H7:J7, J8
Cells with Data Validation
CellAllowCriteria
C2:C4List=Allocation!$E$1:$M$1

Let me take a look at what you got and run some scenerio's to see how it will work. I don't fully understand your expand ranges comment for incresased order size as all your formulas seem to be row based not column based, so if we have one customer order 5 items and the next order 20, what has to change?

Thanks for your help, at first glance, this seems like it could work.
 
Upvote 0
Thanks Mack

When your Customer Id numbers increase expand
=OFFSET(INDIRECT(CELL("address",INDEX(Allocation!$E$1:$M$1,MATCH($C$2,Allocation!$E$1:$M$1,0)))),2,,COUNT(L:L))

When your allocation Batch numbers increase
Add more 1 rows in Column L (Order Tab)
Drag down the order rows so that you return total Batch numbers possible
=IF(ROWS(A$7:A7)>COUNTIF($K$7#,">0"),"",INDEX(Batch,SMALL(IF(
 
Upvote 0
Thanks Mack

When your Customer Id numbers increase expand
=OFFSET(INDIRECT(CELL("address",INDEX(Allocation!$E$1:$M$1,MATCH($C$2,Allocation!$E$1:$M$1,0)))),2,,COUNT(L:L))

When your allocation Batch numbers increase
Add more 1 rows in Column L (Order Tab)
Drag down the order rows so that you return total Batch numbers possible
=IF(ROWS(A$7:A7)>COUNTIF($K$7#,">0"),"",INDEX(Batch,SMALL(IF(
Ok, so it is not fully working when I put it in place on the live sheet. The data columns worked where you pull the allocation data to the order sheet. On the order sheet portion, the Lot # and Quantity is not being populated (lot is returning Name? error and the quantity column is empty. Seems like the array formulas are working but not the regular formulas in column A and D.
 
Upvote 0
Ok, so it is not fully working when I put it in place on the live sheet. The data columns worked where you pull the allocation data to the order sheet. On the order sheet portion, the Lot # and Quantity is not being populated (lot is returning Name? error and the quantity column is empty. Seems like the array formulas are working but not the regular formulas in column A and D.

I got the quantity column to work on the SO table of the order sheet, still looking into why the #NAME? error is coming up in the Lot# column of the SO table. I will keep you updated and if you have an idea on why that formula would not be working, please let me know.
 
Upvote 0
Sounds like Lot # is a new column & not the same as "Batch #"

e.g. =IF(ROWS(A$7:A7)>COUNTIF($K$7#,">0"),"",INDEX(Batche,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS(A$7:A7))))

The Array will return #NAME? when there is no matching matching range, note in the above that Batche doesn't match the named range called Batch in my solution.

Batch=Allocation!$A$3:INDEX(Allocation!$1:$1000,COUNTA(Allocation!$A:$A)+1,1)A7:C7, H7:J7, H8

What column is Lot #? you may need to create the named range.
 
Upvote 0
Sounds like Lot # is a new column & not the same as "Batch #"

e.g. =IF(ROWS(A$7:A7)>COUNTIF($K$7#,">0"),"",INDEX(Batche,SMALL(IF($K$7#>0,ROW($K$7#)-ROW($K$7)+1),ROWS(A$7:A7))))

The Array will return #NAME? when there is no matching matching range, note in the above that Batche doesn't match the named range called Batch in my solution.

Batch=Allocation!$A$3:INDEX(Allocation!$1:$1000,COUNTA(Allocation!$A:$A)+1,1)A7:C7, H7:J7, H8

What column is Lot #? you may need to create the named range.
Sorry, meant to say Batch # not Lot #. But that was it! the named range I had as Batch_# and the formula had Batch. Thank you, I believe it is working as need be. The only thing that isn't totally user hands off is having to insert more rows into the table if the customer orders more than what the table is built for, but this is a better option that what was in place before.

Thank you very much for your help.
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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