简体   繁体   中英

Table Manipulations in Excel VBA

I have the following table on one sheet, top table of the picture, and I need to transform it to the to the different format on the second sheet (bottom table of the picture). I need to use VBA in Excel to do this manipulations. I pulled the main table (top) from SQL query on the separate sheet and need to rearrange it to fit my needs. I have a lot more data than that but it follows the same format. Just imagine that there are just more Shelves, Items, Amounts and Stores.

I searched everywhere but can't seem to find direct answer.

I am relatively new to VBA. Can someone give me a some directions? Is there a website with some tutorials about table manipulations in Excel VBA?

Table_Link_Image

Beyond an intellectual pursuit, there is absolutely no need for VBA. From your example, put this array formula in C24.

=IFERROR(INDEX($B$2:$B$23, MATCH(0, IF(LEN($B$2:$B$23), COUNTIF($B24:B24, $B$2:$B$23), 1), 0)), "")

Finalize with Ctrl + Shift + Enter↵ . Once entered correctly, fill right until you run out of values to retrieve.

In A25 use this standard formula .

=IF(COUNTIF(A$24:A24, MOD(ROW(1:1)-1, MAX(A$2:A$23))+1)<SUMPRODUCT((D$2:D$23<>"")/COUNTIF(D$2:D$23, D$2:D$23&"")), MOD(ROW(1:1)-1, MAX(A$2:A$23))+1, "")

Fill down to get all of the shelves you will need.

In B25 use this array formula ,

=IF(AND(ROW(1:1)>1,COUNTIF(A$24:A25, A25)=COUNTIF(A$24:A24, A24)), B24, IFERROR(INDEX($D$2:$D$23, MATCH(0, IF(LEN($D$2:$D$23), COUNTIF(B$24:B24, $D$2:$D$23), 1), 0)), ""))

Finalize with Ctrl + Shift + Enter↵ . Fill down to catch all of the stores.

Finally, put this in C25.

=SUMIFS($C$2:$C$23, $A$2:$A$23, $A25, $B$2:$B$23, C$24, $D$2:$D$23, $B25)

Fill right to D25 then fill C25:D25 down to the length of the table.

商店库存表

The only difference in my second table is that Water comes before Gartorade and that is a result of it appearing the first table's Item list first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM