Use worksheetfunction.countifs and show Runtime error 1004 Method 'Range' of object '_worksheet' failed

minmark

New Member
Joined
Jul 18, 2016
Messages
44
Dear Gents,
I test the following code and show an error Runtime error 1004 Method 'Range' of object '_worksheet' failed.

Would you please help me to figure out why bold codes have range problem?
Thanks.

Code:
dim rng As Range
dim VD, VC  As Integer
dimi as integer
VD = Sheet1.Cells.Find(what:="VisitD").Column
VC = Sheet1.Cells.Find(what:="VisitC").Column
Sheet7.Select
   ActiveSheet.Unprotect "1234"
   Application.ScreenUpdating = False
Set rng = Cells.Find(what:="Daily Activity Breadkdown").Offset(1, 2).Range("A1")
For i = 0 To Day(Now()) - 1     
     [B]Cells(rng.Row, rng.Column + i).Value = WorksheetFunction.CountIfs(Sheet1.Range(Cells(10, VD), Cells(1010, VD)), i + 1, Sheet1.Range(Cells(10, VC), Cells(1010, VC)), "F") _
      + WorksheetFunction.CountIfs(Sheet1.Range(Cells(10, VD), Cells(1010, VD)), i + 1, Sheet1.Range(Cells(10, VC), Cells(1010, VC)), "FP")[/B]
      Next i
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this.
Code:
    With Sheet1
        Sheet7.Cells(rng.Row, rng.Column + i).Value = Application.CountIfs(.Range(.Cells(10, VD), .Cells(1010, VD)), i + 1, .Range(.Cells(10, VC), .Cells(1010, VC)), "F") _
            + Application.CountIfs(.Range(.Cells(10, VD), .Cells(1010, VD)), i + 1, .Range(.Cells(10, VC), .Cells(1010, VC)), "FP")
    End With
 
Upvote 0

Forum statistics

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