Excel VBA Countifs formula with range of lastrow

bobbyexcel

Board Regular
Joined
Nov 21, 2019
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Can someone please help me on the below formula ..

Here I'm writing 3 different formulas which gives the same result.. but not sure how to write using vba.

Formula 1: In Col L : =COUNTIFS($A$2:$A$18,A2,$C$2:$C$18,C2,$I$2:$I$18,">""",$K$2:$K$18,">"&K2) + 1
Formula 2: In Col M : this formula is from macro recorder..
VBA Code:
Dim Lastrow As Long
Lastrow = Range("L" & Rows.Count).End(xlUp).Row
Range("M2:M" & Lastrow).Formula = "=COUNTIFS(R2C1:R12C1,RC[-12],R2C3:R12C3,RC[-10],R2C9:R12C9,"">"""""",R2C11:R12C11,"">""&RC[-2]) + 1"
[B][U]
Formula 3: In Col L : Now I want to customize with lastrow which is not giving proper results.. Need help on this..
VBA Code:
[/U][/B]
Dim Lastrow As Long
Lastrow = Range("L" & Rows.Count).End(xlUp).Row

Range("M2:M" & Lastrow).Formula = Application.WorksheetFunction.CountIfs( _
 Range("$A$2:$A$" & Lastrow), A2, _
 Range("$C$2:$C$" & Lastrow), C2, _
 Range("$I$2:$I$" & Lastrow), ">""", _
 Range("$K$2:$K$" & Lastrow), ">" & K2) + 1

1656260304211.png
 
Last edited by a moderator:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Nevermind .. I figured it out..

With RANGE("M2:M" & Lastrow)
.FormulaR1C1 = "=COUNTIFS(R2C1:R" & Lastrow & "C1,RC[-12],R2C3:R" & Lastrow & "C3,RC[-10],R2C9:R" & Lastrow & "C9,"">"""""",R2C11:R" & Lastrow & "C11,"">""&RC[-2]) + 1"
.Value = .Value
.NumberFormat = "0"

End With
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
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