Need help with Index / Match in vba (or if there is a better way to do this)

snuffnchess

Board Regular
Joined
May 15, 2015
Messages
68
Office Version
  1. 365
Platform
  1. Windows
I am needing to match data from the ACCFEES sheet with data that is on the Combined sheet based on the "shipment_id" field.

If the description in Column H of Accfees is "freight" then I want to ignore the data all together
Fuel Surcharge from Column H of Accfees place Column I data in Column AL of Combined
Notification fee from Column H of Accfees place Column I data to go in Column AM of Combined
Resi Surchg from Column H of Accfees place Column I data to go in Column AN of Combined
Addr Correction from Column H of Accfees place Column I data to go in Column AO of Combined

And everything else from Column H of Accfees to add together column I and put in Column AP of Combined.

AQ of Combined would be the Sum of Columns AL:AP

Alternatively,Is there a way to just have the macro create it's own column names based off of the information that appears in Accfees column H, and then just puts the data in column I into that column? Not sure which is the easiest / best way to go about this?

How would I even begin to do something like this??

Here is what the "Combined" worksheet looks like
History.xlsm
AAJAKALAMANAOAPAQ
1 shipment_id(4) Subtotal Total Fuel SurchargeNotificationResidentialAddress CorrectionOtherTotal Accessorial
2149177149$ 30
3149191850$ 487$ 1,371
4149178437$ 146$ 168
5149021678$ 10$ 15
6149011416$ 148$ 186
7149021679$ 11$ 16
8149021680$ 31$ 34
9149178347$ 249$ 312
10149021681$ 11$ 12
11149021682$ 31$ 34
12149021683$ 29$ 36
13149021684$ 14$ 16
14149021685$ 34$ 37
15149021686$ 51$ 55
16149021687$ 11$ 12
17149021688$ 10$ 11
18149021689$ 9$ 10
19149021690$ 11$ 15
20149021691$ 12$ 13
21149021692$ 11$ 12
22149180784$ 217$ 285
23149183129$ 172$ 207
24149021677$ 31$ 36
25149021693$ 11$ 30
26149021694$ 11$ 12
27149021695$ 12$ 18
28149021696$ 11$ 12
29149021697$ 15$ 20
30149021698$ 10$ 11
31149182866$ 137$ 178
32149011415$ 157$ 177
33149009220$ 156$ 210
34149021699$ 40$ 73
35149021700$ 44$ 78
36149186011$ 202$ 229
37149196173$ 290$ 367
38149180185$ 130$ 146
39149009218$ 225.48$ 253.50
40149021701$ 12$ 18
41149021706$ 6
42149188784$ 207$ 277
43149178346$ 127$ 160
44149182864$ 258$ 326
45149183127$ 567$ 717
Combined




Here is what the data on the "ACCFEES" worksheet looks like

History.xlsm
DEFGHI
1 shipment_id(4) transaction_type(25) transaction_id(4) code(50) description(50)Rate
2149009218400Freight225.48
3149009218UNIFSCFuel Surcharge28.02
4149009220400Freight155.86
5149009220UNIFSCFuel Surcharge54.05
6149011415400Freight156.58
7149011415UNIFSCFuel Surcharge20.35
8149011416400Freight147.74
9149011416UNIFSCFuel Surcharge38.12
10149021677400Freight30.8
11149021677EVCDeclared Value1.8
12149021677FUEFuel Surcharge2.93
13149021678400Freight10.19
1414902167810Del Area Fee3.1
15149021678FUEFuel Surcharge1.23
16149021679400Freight11.22
17149021679FUEFuel Surcharge1.32
1814902167910Del Area Fee3.1
19149021680400Freight31.36
20149021680FUEFuel Surcharge2.9
21149021681400Freight10.84
22149021681FUEFuel Surcharge1
23149021682400Freight30.82
24149021682FUEFuel Surcharge2.85
25149021683400Freight28.82
26149021683010ERemote Area Chg3.7
27149021683FUEFuel Surcharge3.01
28149021684400Freight14.28
29149021684FUEFuel Surcharge1.32
30149021685400Freight33.63
31149021685FUEFuel Surcharge3.11
32149021686400Freight50.64
33149021686FUEFuel Surcharge4.68
34149021687400Freight11.22
35149021687FUEFuel Surcharge1.04
36149021688400Freight9.9
37149021688FUEFuel Surcharge0.92
38149021689400Freight9.22
39149021689FUEFuel Surcharge0.85
40149021690400Freight10.63
4114902169010Del Area Fee3.1
42149021690FUEFuel Surcharge1.27
43149021691400Freight12.35
44149021691FUEFuel Surcharge1.14
45149021692400Freight10.94
46149021692FUEFuel Surcharge1.01
47149021693400Freight10.84
48149021693AAJ-00Addr Correction18
49149021693FUEFuel Surcharge1.03
50149021694400Freight11.22
51149021694FUEFuel Surcharge1.07
52149021695400Freight11.62
53149021695REPResi Surchg4.45
54149021695FUEFuel Surcharge1.53
55149021696400Freight11.22
56149021696FUEFuel Surcharge1.07
57149021697400Freight14.87
5814902169710Del Area Fee3.1
59149021697FUEFuel Surcharge1.71
60149021698400Freight10.19
61149021698FUEFuel Surcharge0.97
62149021699400Freight39.86
63149021699690-AHAddl Handling Weig27
64149021699FUEFuel Surcharge6.35
65149021700400Freight44.05
66149021700690-AHAddl Handling Weig27
ACCFEES
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello

What version of Excel do you have?
 
Upvote 0
Here's a formula solution if you can use it, I converted ACCFEES data to a table so that Combined can calculate as you add more data.

The Combined Sheet has all the actual Descriptions from the descriptions column except freight. Note that for the Index formula to work some of the ACCFEES header names had spaces before and after their names which I removed for proper matches.

The Combined header names are Data Validated so you can change the column order as required.

Need help with IndexMatch in vba_History.xlsx
AAJAKALAMANAOAPAQARASATAUAV
1 shipment_id(4) Subtotal Total Fuel SurchargeDeclared ValueDel Area FeeRemote Area ChgResi SurchgAddr CorrectionAddl Handling WeigOtherTotalDescriptions
2149177149$30.00         Fuel Surcharge
3149191850$487.46$1,371.12         Declared Value
4149178437$145.63$167.95         Del Area Fee
5149021678$10.19$14.52$1.23 $3.10    $14.52$18.85Remote Area Chg
6149011416$147.74$185.86$38.12      $185.86$223.98Addr Correction
7149021679$11.22$15.64$1.32 $3.10    $15.64$20.06Resi Surchg
8149021680$31.36$34.26$2.90      $34.26$37.16Addl Handling Weig
9149178347$249.18$312.35         
10149021681$10.84$11.84$1.00      $11.84$12.84
11149021682$30.82$33.67$2.85      $33.67$36.52
12149021683$28.82$35.53$3.01  $3.70   $35.53$42.24
13149021684$14.28$15.60$1.32      $15.60$16.92
14149021685$33.63$36.74$3.11      $36.74$39.85
15149021686$50.64$55.32$4.68      $55.32$60.00
16149021687$11.22$12.26$1.04      $12.26$13.30
17149021688$9.90$10.82$0.92      $10.82$11.74
18149021689$9.22$10.07$0.85      $10.07$10.92
19149021690$10.63$15.00$1.27 $3.10    $15.00$19.37
Combined
Cell Formulas
RangeFormula
AL2:AR19AL2=IFNA(INDEX(ACCFEESTBL[Rate],MATCH($A2&AL$1,INDEX(ACCFEESTBL[shipment_id(4)]&ACCFEESTBL[description(50)],),0)),"")
AS2:AS19AS2=SUMIFS(ACCFEESTBL[Rate],ACCFEESTBL[shipment_id(4)],A2)
AT2:AT19AT2=SUM(Combined!$AL2:$AS2)
Cells with Data Validation
CellAllowCriteria
AL1:AR1List=$AV$2:$AV$8
 
Upvote 0
Solution
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Help with Index/Match
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,573
Members
449,089
Latest member
Motoracer88

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