PDA

View Full Version : VBA to loop through each row and subtract if conditions met



BrutalDawg
02-06-2017, 11:36 AM
I have two sheets, sheet1 and sheet2.

I have trying to come up with a macro that loops through each row in sheet1 and subtracts sheet1!I from sheet2!F if Sheet2!A2=Sheet1!E2 & Sheet2!D2=Sheet1!H2 until 0 and then find the next row in sheet2 where Sheet2!A2=Sheet1!E2 & Sheet2!D2=Sheet1!H2 until there is 0 remaining on sheet1.

Hope the attachment helps.

Note, some items on sheet1 will not correlate with anything on sheet2

18265

SamT
02-06-2017, 12:28 PM
Sheet 1 is items shipped?
Sheet 2 is items Ordered?

And you want Sheet2, column H to reflect the number of Items not yet shipped?


I have trying to come up with a macro that loops through each row in sheet1 and subtracts sheet1!I from sheet2!F if Sheet2!A2=Sheet1!E2 & Sheet2!D2=Sheet1!H2 until 0 and then find the next row in sheet2 where Sheet2!A2=Sheet1!E2 & Sheet2!D2=Sheet1!H2 until there is 0 remaining on sheet1.
Please restate that using Header names.

BrutalDawg
02-06-2017, 12:40 PM
Hello Samt,

Yes Sheet1 is items shipped and sheet2 is items ordered. Sorry for the confusion, what i am trying to do is have a macro loops through sheet1 and subtracts the quantity in given row from sheet 2 if sheet1 Ship to address1 matches sheet2 place, and sheet1 item matches sheet2 item.

Important to note, same item can ship to different locations.

Thanks for the help!