Looping with a Worksheet Function

termeric

Active Member
Joined
Jun 21, 2005
Messages
280
Can anyone point put what I am doing wrong here? I want to loop through a few rows on one tab using a worksheet function to return countif and sum values. I'm getting a Method "Range" of object "_Global" failed error when I try to run it. This was working before I tried to add I + 9 to so that I could loop through this.


Code:
For i = 1 To 33
    linecount = Application.WorksheetFunction.CountIf(Range("D" & i + 9 & ":BC " & i + 9), ">0")
    linesum = Application.WorksheetFunction.Sum(Range("D" & i + 9 & ":BC " & i + 9))

    Sheets("Sheet1").cell(i + 1, 2).Value = linecount
    Sheets("Sheet1").cell(i + 1, 3).Value = linesum
    
Next I
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You need to remove the space from ":BC "
 
Upvote 0
Among other things..
is the space created after the BC in ":BC " on both lines 2 & 3 creating a problem - Remove and try again
Also, your Next I - why not change that to lowercase i.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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