I have two comments.

1) If I correctly understand what you are trying to accomplish, you
could simply put the formula COUNTIF(AR2:CE2,1) in cell K2 and copy it
down to K3:K250.

2) It seems to me that the problem with your code is that your COUNIF
formula references the whole range (arange) not such a single row.
Give this modified version a try:

    Dim aRange As Range
    Dim WS1 As Worksheet
    Set WS1 = Worksheets("Dept")
    Set aRange = WS1.Range("$AR$2:$CE$250")
    Dim row As Range
    For Each row In aRange.Rows
        WS1.Cells(row.Cells(1, 1).row, "K").Value =
Application.WorksheetFunction.CountIf(row, ">0")
    Next row

Hope this helped.

On Oct 2, 7:01 am, c <cad...@gmail.com> wrote:
> Hi Everyone,
>
> Need some help with this macro.  Basically, I am searching through
> rows and looking for any values in the cells that are >0 in columns AR
> - CE.
> After I find these cells in that range, I need to count the number of
> columns.  This can be done with the COUNTIF function.  I also do not
> want to count blank cells.
>
> I want to put the result of the countif in the K column.
>
> Here is what I have so far and it's not working.  Go figure.  Please
> help.  I think I'm close.
>
> Dim j, k As Long
> Dim iRow As Long
> Dim aRange As Range
> Dim NumberOfMonths As Long
>
> Dim WS1 As Worksheet
> Set WS1 = Worksheets("Dept")
>
> NumberOfMonths = 0
>
> Sheets("Dept").Select
> With WS1.Range("AR2:CE250")
> Set aRange = WS1.Range("$AR$2:$CE$250")
> For j = 2 To aRange.Rows.Count
>      For k = 44 To 90
>        If ((WS1.Cells(j, k) > 0)) Then
>             NumberOfMonths = Application.WorksheetFunction.CountIf
> (aRange, ">0")
>            WS1.Cells(j,11).Value = NumberOfMonths
>   End If
>      Next k
> Next j
> End With

--~--~---------~--~----~------------~-------~--~----~
----------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 6,500 subscribers worldwide and receive many nice notes about the 
learning and support from the group. Our goal is to have 10,000 subscribers by 
the end of 2009. Let friends and co-workers know they can subscribe to group at 
http://groups.google.com/group/excel-macros/subscribe
-~----------~----~----~----~------~----~------~--~---

Reply via email to