VBA – Swap values

Hi, I have a large dataset, about 4000 rows, which I need to correct some values in case of a criteria. Below is the example of my data:

Order ID Product Type Dollar Amount
11 Low grade 20
11 Premium 35
11 Low grade 10
12 Premium 50
12 Premium 20
12 Low grade 10
12 Low grade 40
12 Low grade 45
12 Premium 30



In each of distinct order IDs, the dollar amount of premium products must be higher than low grade ones. As seen in my data, for order ID “11”, there is no issue since premium one is larger than low grade ones: 35>20>10.

But in order ID “12”, as it is seen, there are two low grade orders which have higher dollar values than two of the premium ones. To fix this issue, I must swap the value of the low grade ones (40,45) with the premium ones (20,30). So, after correction, the data should look like the following:


Order ID Product Type Dollar Amount
11 Low grade 20
11 Premium 35
11 Low grade 10
12 Premium 50
12 Premium 40
12 Low grade 10
12 Low grade 20
12 Low grade 30
12 Premium 45



I have similar issues with many of the order IDs in my dataset which I need a VBA code to go through all the order IDs and fix this issue if exists.

By: Sam

110 thoughts on “VBA – Swap values

  1. Jasa Fotocopy Murah

    Please let me recognize if you’re trying to find a good author for your web site. You may have some great articles, and I think I might be a good advantage. Should you ever want to acquire some of the weight off, I’d like to be able to write some material intended for your blog in change to get a link back to be able to mine. Please shoot me personally an email if serious. Thanks.

  2. bus pariwisata murah

    I simply desired to thank you therefore much again. I are not sure the issues that I would possess gone through without typically the form of hints revealed simply by you regarding that scenario.

Comments are closed.