mardi 14 mai 2019

How to use if statement to match multiple criteria and delete selected rows in table

I'm trying to figure out an IF function that will delete specific rows in a table when criteria not met, to be used in VBA code when I manage to get the function working.

I've got a table with the following headings:

Article UOM Site    SOH

5855    CS  M01     0.25
5855    SW  M01     0
5855    CS  M04     49
5855    SW  M04     58
5855    SW  M04L    0
5855    CS  M04L    0
30623   SW  M01     142.08
30623   CS  M01     0
30623   SW  M01L    297.42
30623   CS  M01L    0
194272  CS  M27L    11.5
194272  SW  M27L    0
198552  SW  M27     0
198579  SW  M01     80
198579  SW  M04     109
228803  SW  M14     4.67
228803  CS  M14     3.29
344486  CS  M15L    0
344486  SW  M15L    -0.17
373926  SW  M18L    0
373926  CS  M18L    0

If tried different IF and MATCH functions, but it's not working as it should because I'm not sure how to word it anymore.

The code/formula should work something like this:

  1. IF the "Article" and "Site" is the same as another row, THEN
  2. check "SOH" and choose the one not =0 (could be + or - value), BUT
  3. IF both are =0 or both have values, THEN
  4. Choose the one with "UOM" =CS
  5. DELETE the other row not chosen above.

EXAMPLE 1

  1. First 2 lines have the same "Article" and "Site"
  2. "SOH" for the 1st line has a value not =0, where the 2nd line =0, so choose the 1st line
  3. not applicable
  4. not applicable
  5. DELETE 2nd line

EXAMPLE 2

  1. Line 3 and 4 have the same "Article" and "Site"
  2. not applicable, next option
  3. both have values THEN
  4. choose 3rd line because "UOM"=CS
  5. DELELTE 4th line

If anyone has any easier ways, it would be appreciated. I want to use the formula with the rest of my VBA code.

Aucun commentaire:

Enregistrer un commentaire