I could use some help writing this Macro. Its over my head. Please use comments between lines on the Macro to explain what each function is doing. I am trying to learn a little more about writing VBA and the comments help considerably. Thanks.

Step 1
I have data on one sheet called CPReport.xlsx (CP) which is a variable length sheet that changes every day. Column “B” of CP has order#s that match order#s in column “I” of my main sheet called DockSchedule.xls (DS).

What I need is VBA for my macro that compares "I" in DS to "B" in CP and if there is a match returns the value in "C" from CP to "M" in DS.

Here is some bad syntax for logic: IF(sheetDS "I" = sheet CP 'B", sheetDS "L" = sheetCP "C")

L2=VLOOKUP($I2,[CPReport.xlsx]Sheet1!$B$2:$B$200,COLUMN(3),0)

Not sure if this VLOOKUP has the correct syntax.[table="width: 200, class: grid, align: left"]


Step 2

The data in column “H” of DS has duplicating values called Master Ship# (MS). I want to delete the duplicate lines; however, a calculation must be performed based upon Column “I” first.

Column “I” on DS is Order# (ON); there can be multiple “ON’s” tied to the MS in “H”, the calculation that needs to be done is from numbers in Column L. These are Case Pick (CP) quantities transferred from step1.

What I need done is for the quantities in “L” to be summed IF the MS in “H” is the same. The result of the SUMIF can be put into column M if needed. Here's the tricky part that I am clueless on:

I want the rows deleted that contain the duplicate MS but I want to keep the line that has the largest value in M after the SUMIF function runs.