VBA - sum & countif & for loop

HaHa1712

New Member
Joined
Jan 12, 2018
Messages
2
Hi, Bros.
I am having trouble coming up with a formula and was wondering if I could get some assistance/advice.


I have 2 sheets, "Data" and "Sheet1".

The sheet "Data" have 100000 rows with data from column B to column H.

[TABLE="width: 182"]
<colgroup><col><col span="7"></colgroup><tbody>[TR]
[TD]ID1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]8[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]2[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]ID2[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]9[/TD]
[TD]3[/TD]
[TD]5[/TD]
[TD]9[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]ID3[/TD]
[TD]7[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]6[/TD]
[TD]8[/TD]
[TD]6[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]ID4[/TD]
[TD]1[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]9[/TD]
[TD]4[/TD]
[TD]3[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]ID5[/TD]
[TD]4[/TD]
[TD]7[/TD]
[TD]0[/TD]
[TD]3[/TD]
[TD]9[/TD]
[TD]3[/TD]
[TD]6[/TD]
[/TR]
</tbody>[/TABLE]

The cell (A2) and cell (B1) in sheet "Sheet1" are the criteria.

A2 =1, B1 =0


How to transform the code below into VBA Code (or another method)?
In sheet 1 Cell(2,2) =
IF(COUNTIF(Data!$1:$1,$A2)=0,0,COUNTIF(Data!$1:$1,B$1))+
IF(COUNTIF(Data!$2:$2,$A2)=0,0,COUNTIF(Data!$2:$2,B$1))+
IF(COUNTIF(Data!$3:$3,$A2)=0,0,COUNTIF(Data!$3:$3,B$1))+
.
.
.
IF(COUNTIF(Data!$10000:$10000,$A2)=0,0,COUNTIF(Data!$10000:$10000,B$1))


Thank you very much.
 

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

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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