Forum

WorksheetFunction.C...
 
Notifications
Clear all

WorksheetFunction.Countifs not Work VBA

3 Posts
2 Users
0 Reactions
102 Views
(@kpmsivaprakasam2003)
Posts: 15
Eminent Member
Topic starter
 

Hi

I am using Excel 2013

I need the "Number of Customer duplicate" find out in the "E" Column in VBA

Data is in "C" Column, Result is "E" Column

I trying the code below, but not working, they have come to all return the "1" count, the correct count is in "D" Column through "=COUNTIFS($C$2:C2,C2)"

My Data is (more than 1 lakh row) long, so I apply the formula getting a long time, few data is deleted for upload purpose to this your site.

So, trying VBA "WorksheetFunction.Countifs"

Macro Code:

Sub Countifs1()
Dim lastRow As Long
Dim thisRow As Long

With Sheets("Sheet1")
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For thisRow = 2 To lastRow
.Cells(thisRow, "E").Value = WorksheetFunction.Countifs(ThisWorkbook.Sheets("Sheet1").Range("$C$2:C2"), ThisWorkbook.Sheets("Sheet1").Range("C2"))
Next thisRow
End With
End Sub

Thanks for Help

 
Posted : 17/12/2020 2:44 am
(@fluff)
Posts: 36
Eminent Member
 

The problem is that you are using a static range in the COUNTIFS, you need to increment the row like

.Cells(thisRow, "E").Value = WorksheetFunction.Countifs(.Range("$C$2:C" & thisRow), .Range("C" & thisRow))

 
Posted : 17/12/2020 8:43 am
(@kpmsivaprakasam2003)
Posts: 15
Eminent Member
Topic starter
 

thank u for this work . . . 

 
Posted : 05/01/2021 5:57 am
Share: