+ Reply to Thread
Results 1 to 3 of 3

Thread: Count Non-Blank cells in range for each row

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2003, 2007, 2010
    Posts
    758

    Count Non-Blank cells in range for each row

    I am trying to count the number of non-blank cells in columns B-F and paste the value in column H. I am trying to define the range for each row but can't get the syntax correct. Any help appreciated. Thanks.

    Sub aa()
    
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
        For x = 2 To LastRow
            Agents = WorksheetFunction.CountA(Range("B" & x).("F" & x)
            Range("H" & x) = Agents
        Next
    
    End Sub
    Last edited by maacmaac; 01-07-2012 at 04:24 PM.

  2. #2
    Forum Moderator Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    5,953

    Re: Count Non-Blank cells in range for each row

    Perhaps try:
    Agents = WorksheetFunction.CountA(Range("B" & x & ":F" & x))
    Range("H" & x).Value = Agents
    or just
    Range("H" & x).Value = WorksheetFunction.CountA(Range("B" & x & ":F" & x))

  3. #3
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Count Non-Blank cells in range for each row

    Sub snb()
      for each cl in columns(1).specialcells(2)
        cells(cl.row,8)=cl.entirerow.specialcells(2).count
      next
    End Sub



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0