VBA Code to loop through Array and with criteria

Wafee

Board Regular
Joined
May 27, 2020
Messages
104
Office Version
  1. 2013
Platform
  1. Windows
I have below code where we arrived at the list based on criteria and I have assigned it to an array called arr1. Now I am looking to apply a filter in "K" colum to select "Yes" alone loop through this array of items which are in "I" column and get the total sum from R column. I am fine if array is not to be used and we can loop through the list.

Sub Dcount()
Dim Lastrow As Long
Dim Rng As Range
Dim List As Object
Dim Listcount As Long
Dim arr1 as Variant
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set List = CreateObject("Scripting.Dictionary")
With Range("A1:I1")
.AutoFilter 1, "Temp", xlOr, "tem"
.AutoFilter 5, "MX"
End With
For Each Rng In Range("I2:I" & Lastrow).SpecialCells(xlVisible)
List(Rng.Value) = empty
Next Rng
ActiveSheet.AutoFilterMode = False
arr1 = Application.Transpose(Array(List.Keys, List.Items))
 
Sorry, but I'm not understanding what the ultimate goal is.
Do you only want the sum according to some criteria?
I am really sorry if it is confusing. Leave all the above code and consider that I have few items in array called arr1 = (item1,item4,item6) and these items will be there in "I" column of the worksheet. Now I want to filter "CX" in F column and and then if it the item is there in "I" column then it should get value from "R" column. There might be multiple lines for singles item.
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Leave all the above code and consider that I have few items in array called arr1 = (item1,item4,item6) and these items will be there in "I" column of the worksheet. Now I want to filter "CX" in F column and and then if it the item is there in "I" column then it should get value from "R" column.
But the result of the sum, you want it in a msgbox or in a cell, because to make the sum it is not necessary to use the arrays, perhaps the sumifs formula.
 
Upvote 0
Now I want to filter CX in sheet and find the total sum from R column against my arr1 items. In this case total sum would be 665. item1 - 100,103,109; item4- 119; item6 - 114, 120.

How about:

Dante Amor
AFIRST
1Head1Head6Head9Head18
2TempCXItem1100665
3TempCXItem2112
4TempMXItem3101
5TempMXItem4113
6TempMXItem5102
7TempCXItem6114
8TempCXItem1103
9TempCXItem2115
10TempCXItem3104
11TempMXItem4116
12TempMXItem5105
13TempMXItem6117
14TempMXItem1106
15TempMXItem2118
16TempMXItem3107
17TempCXItem4119
18TempCXItem5108
19TempCXItem6120
20TempCXItem1109
Sheet2
Cell Formulas
RangeFormula
T2T2=SUM(SUMIFS(R2:R20,F2:F20,"CX",I2:I20,{"Item1","Item4","Item6"}))
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,037
Members
449,205
Latest member
Eggy66

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