+ Reply to Thread
Results 1 to 10 of 10

Formula or VBA or Combination to count Number of Cells in a merged range! PLEASE HELP!

Hybrid View

WaylettChris Formula or VBA or Combination... 11-12-2014, 11:32 AM
Jonmo1 Re: Formula or VBA or... 11-12-2014, 11:53 AM
Ron Coderre Re: Formula or VBA or... 11-12-2014, 12:00 PM
WaylettChris Re: Formula or VBA or... 11-12-2014, 01:31 PM
Ron Coderre Re: Formula or VBA or... 11-12-2014, 01:58 PM
WaylettChris Re: Formula or VBA or... 11-13-2014, 10:53 AM
TMS Re: Formula or VBA or... 11-12-2014, 12:07 PM
samba_ravi Re: Formula or VBA or... 11-12-2014, 01:39 PM
ChemistB Re: Formula or VBA or... 11-12-2014, 03:00 PM
samba_ravi Re: Formula or VBA or... 11-13-2014, 11:02 AM
  1. #1
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Formula or VBA or Combination to count Number of Cells in a merged range! PLEASE HELP

    If you're interested in a VBA solution:
    This User Defined Function returns the count of matching cells in a range.
    - Unmerged cells count as 1
    - Cells in merged areas each count as 1

    • ALT+F11...to open the Visual Basic Editor
    • Select the workbook name that will contain the function
    (in the Project - VBAProject window)
    • Insert.Module
    • Copy the below code and paste in into that module:

    Function CountMatchedCells(FindText As String, rRange As Range) As Integer
    Dim cCell As Range
    Dim iCtr As Integer
    Application.Volatile
    
    For Each cCell In rRange.Cells
        If cCell.Value = FindText Then
            If cCell.MergeCells = True Then
                iCtr = iCtr + cCell.MergeArea.Cells.Count
            Else
                iCtr = iCtr + 1
            End If
        End If
    Next cCell
    CountMatchedCells = iCtr
    End Function
    Sample usage of that function to count the cell blocks in your sample workbook
    B21: =CountMatchedCells("LFB",B1:B20)

    In that example, the formula returns: 8
    There are 3 areas containing "LFB"
    -B1:B4
    -B7
    -B18:B20

    Is that something you can work with?
    Last edited by Ron Coderre; 11-12-2014 at 12:10 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  2. #2
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Tetbury, England
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    105

    Re: Formula or VBA or Combination to count Number of Cells in a merged range! PLEASE HELP

    Hi Ron!

    At the moment it seems out of all the responses, yours will probably fit my needs the best (assuming this next request comes off!).

    How would I ammend your "CountMatchedCells" formula to look at the first x numbers of the text string in the cells, to see if it matches LFB. Some of the team input the project initials and a brief description of the task carried out (in case they forget!).

    Example...in the cell it says "LFB - Answering emails", how can I make the formula just look for the first 3 letters?

    Thanks in advance for your help!

    Regards,



    Chris

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Formula or VBA or Combination to count Number of Cells in a merged range! PLEASE HELP

    Here you go...try this:

    Function CountMatchedCells(FindText As String, rRange As Range) As Integer
    Dim cCell As Range
    Dim iCtr As Integer
    Application.Volatile
    
    For Each cCell In rRange.Cells
        If cCell.Value Like FindText Then
            If cCell.MergeCells = True Then
                iCtr = iCtr + cCell.MergeArea.Cells.Count
            Else
                iCtr = iCtr + 1
            End If
        End If
    Next cCell
    CountMatchedCells = iCtr
    End Function
    Then you can use wildcards in the FindText

    Examples:
    This formula counts areas that begin with "LFB" (notice the asterisk after LFR)
    B21: =CountMatchedCells("LFB*",B1:B20)
    and this one counts areas that contain "LFB"
    B21: =CountMatchedCells("*LFB*",B1:B20)
    Does that help?

  4. #4
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Tetbury, England
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    105

    Re: Formula or VBA or Combination to count Number of Cells in a merged range! PLEASE HELP

    Ron,

    Genius! Thanks a lot! Works Perfectly!

    Thank you to everyone else who posted too, very grateful to you all, people like all of you make this forum what it is!

    Ron's just happened to work best for me personally is all.

    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Question: Count Unique/Duplicated 5 number Combination
    By david gonzalez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2013, 11:43 PM
  2. Formula checking if a combination of cells exists in the range
    By chrismyers51 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-05-2013, 05:49 PM
  3. Replies: 5
    Last Post: 01-03-2012, 12:35 PM
  4. Replies: 9
    Last Post: 02-24-2010, 07:20 AM
  5. [SOLVED] Count number of characters in merged cells + adjusting rowheight
    By Luc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2006, 07:00 PM

Tags for this Thread

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