+ Reply to Thread
Results 1 to 3 of 3

counting number of rows

Hybrid View

  1. #1
    Registered User
    Join Date
    06-16-2013
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    8

    counting number of rows

    I have two worksheets- Sheet1 and Sheet2

    In Sheet1, I want to count the number of row are not bold. And I want to show this count in a cell in Sheet2.

    I currently have something like this:

    Dim cnt as Integer
    
    cnt = Range("G1").CurrentRegion.Rows.Count
     
     For Each Row In Range("G1")
         If Row.Font.Bold = True Then
            cnt = cnt + 0
    
    End If
    Next
    
        Application.Goto (ActiveWorkbook.Sheets("Sheet2").Range("B2"))
        ActiveCell.Value = cnt
    But the macro is returning me the count of all the rows instead, including the bold ones.

    How should I change the macro?

    Thanks!

    Moderator's note: Code tags added for you - this time
    Last edited by FDibbins; 06-23-2013 at 12:32 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: counting number of rows

        Dim cnt As Long, cell As Range
        
        For Each cell In Range("G1", Range("G" & Rows.Count).End(xlUp))
            If cell.Font.Bold Then cnt = cnt + 1
        Next
        
        Application.Goto ActiveWorkbook.Sheets("Sheet2").Range("B2")
        ActiveCell.Value = cnt
    Note: this method doesn't count Bold as a result of conditional formatting.
    Last edited by AlphaFrog; 06-22-2013 at 11:59 PM.

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: counting number of rows

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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.6.0 RC 1