VBA - Find value of previous cell based on criteria

weissihm

New Member
Joined
May 21, 2015
Messages
8
I'm trying to find a way to identify how much inventory (INTOnHand), for each item (INTItem), was on hand when a PO was received in the system.

Each row is an inventory transaction and I have everything sorted by item (INTItem) and Date(INTDate). The code does not need to sort, just find the correct data. This is just a sample of the data. The real data has varying numbers of rows, but the columns are always the same.

I'm looking for VBA code to loop through the data. For each INTItem, look at INTType. If INTType = PO, return the the value in INTOnHand of the previous row where INTType does not = PO. Put the value in column P. If there is not a previous INTType <> PO for that item, column P can remain blank.

Example:
Row 10, the INTType =PO, I would like the value in INTOnHand from row 9 (the most previous transaction whose INTType <> PO), so cell P10 would now =301
Row 12, the INTType =PO, I would like the value in INTOnHand from row 9 (the most previous transaction whose INTType <> PO), so cell P12 would now =301

1585325706969.png


I'm fairly new to VBA, so any help you give will be greatly appreciated. Thank you.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,039
Latest member
Mbone Mathonsi

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