VBA: Copy Unique values from table based on certain condition

wjeil

New Member
Joined
Feb 25, 2022
Messages
37
Office Version
  1. 365
Platform
  1. Windows
Hello,

I want to copy the Unique Order ID from A2:A to H2:H based on a certain condition. If it is a singlepick (column E "Yes") I should not be copied to H. The example should result in a list at H of 9 rows without Order 2.
I only want to do this on command so VBA in combination with a button would be preferred.

How can I do this via VBA?



Map2
ABCDEFGH
1OrderIDSKU.IDColliAmountLOC.IDSINGLEPICKORDERS
2Order 1B1043H05.001NO
3Order 2A151H01.013YES
4Order 3A314H02.006NO
5Order 3A82H01.004NO
6Order 4A214H02.005NO
7Order 4B1321H04.010NO
8Order 4B151H03.016NO
9Order 5C732H01.043NO
10Order 5A281H02.013NO
11Order 6A493H02.009NO
12Order 7B572H03.019NO
13Order 7A361H01.020NO
14Order 7A63H01.003NO
15Order 7A77H01.001NO
16Order 7A167H02.008NO
17Order 7A213H02.005NO
18Order 7A412H03.003NO
19Order 7A82H01.004NO
20Order 8A392H01.007NO
21Order 8B121H03.022NO
22Order 8B1861H03.015NO
23Order 8A261H03.003NO
24Order 8A423H02.009NO
25Order 8A212H02.005NO
26Order 8A182H04.003NO
27Order 8A351H03.005NO
28Order 8A163H02.008NO
29Order 8B1181H03.017NO
30Order 9C262H05.038NO
31Order 10B1231H04.007NO
32Order 10A462H02.012NO
33Order 10A882H01.018NO
Blad1
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How about
VBA Code:
Sub wjeil()
   Dim Ary As Variant
   
   With Range("A2", Range("A" & Rows.count).End(xlUp))
      Ary = Evaluate("unique(filter(" & .Address & "," & .Offset(, 4).Address & "<>""Yes""))")
   End With
   With Range("H2")
      .Resize(10000).ClearContents
      .Resize(UBound(Ary)).Value = Ary
   End With
End Sub
 
Upvote 0
Solution
Thanks!! One question what if i want to paste it on another worksheet in A?
 
Upvote 0
You just need to change the range from H2, to wherever you want it.
 
Upvote 0

Forum statistics

Threads
1,215,202
Messages
6,123,625
Members
449,109
Latest member
Sebas8956

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