Complex Countif

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,868
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I've run into a bit of a hurdle with some logic for some code:

I have a dynamic database, in my example, consisting of 46 rows (row 1 is header). variable lastrow holds the calculated number of rows in the database (46)

Column CW is a result of formula .range("CW" & rnum1) = .range("E" & rnum1) + .range("S" & rnum1). rnum1 is the row number of the current record being worked on. In this example, rnum1 = 2.

The value created will be semi-unique from the other records in the database, and will take a format of DRHPL1 (DR = .range("E2")), and (HPL1 = .range("S2))

This is where I am struggling. In column CX, I need to calculate how many times the value "DR"+that row's value of column S occurs in the entire column CW. In this example, CX2 = the number of occurrances of "DRHPL1" (DR+S2(HPL1) in range CW:CW. CX will be populated for each row in the database unique to it's corresponding value in CW.

Here is my failed attempt:
Code:
        lastrow = .Range("A" & Rows.Count).End(xlUp).Row
        .Range("CX2:CX" & lastrow) = Application.CountIf(.Range("CW:CW"), "DR" + .Range("S" & ???))

I hope I was able to explain myself clearly. It was awkward.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

AD_Taylor

Well-known Member
Joined
May 19, 2011
Messages
687
You could try:

Code:
        lastrow = .Range("A" & Rows.Count).End(xlUp).Row        
        .Range("CX2:CX" & lastrow) = Application.CountIf(.Range("CW:CW"), .Range("E" & rnum1) & .Range("S" & rnum1))

HTH!
 

Watch MrExcel Video

Forum statistics

Threads
1,129,361
Messages
5,635,808
Members
416,884
Latest member
leeshjay

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
Top