+ 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!

  1. #1
    Registered User
    Join Date
    07-26-2012
    Location
    Tetbury, England
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    73

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

    Hi everyone,

    Now before we get cracking, I know how bad Merged Cells are, but trust me, I have no way around it. I have created a visual diary in Excel to track how much time people in my office are spending on projects. Each Cell represents a block of time, let's say 15 Minutes, and then if a member of staff works on a project for 3.5 hours, they select 14 cells in that day's column, merge them, and input the initial of the project, which then gets automatically coloured using conditional formatting. This is the quickest and most efficient input method that ALSO allows me to see the days too and how they break down, rather than just a lump sum of the total time they spend that day...if that all makes sense...

    Then at the bottom of each column I was looking to have a cell for each formula which would effectively count how many cells are occupied by each initial INCLUDING COUNTING ALL THE CELLS IN THE MERGED RANGES.

    I have attached a spreadsheet as an example which should illustrate my point, but of course, if there are any questions, please do ask me and I will answer!

    Also, apologies if I listed in the wrong section, as not sure what the best solution is. Would prefer forumlas if I can have it rather than VBA, but happy to use some VBA to create functions of what have you that then feed into a formula?!

    Thanks!




    Chris
    Attached Files Attached Files

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

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

    I'll avoid the 'merged cells are bad' discussion. It usually goes nowhere anyway..

    I'd use a helpler column, Say column C for example
    C1: =LOOKUP(REPT("z",255),B$1:B1)
    Filled down to C20

    Then you can use standard countif functions based on column C
    =COUNTIF(C1:C20,"LFB")

  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

    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:

    Please Login or Register  to view this content.
    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

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

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

    User Defined Function (UDF)

    Please Login or Register  to view this content.

    C1:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    copied down

    B21:
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    07-26-2012
    Location
    Tetbury, England
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    73

    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

  6. #6
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

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

    See the attached file
    =SUM(IFERROR(SMALL(IF($B$1:$B$20<>"",ROW($B$1:$B$20)),MATCH(SMALL(IF($B$1:$B$20="LMS",ROW($B$1:$B$20)),ROW(INDIRECT("1:"&COUNTIF($B$1:$B$20,"LMS")))),SMALL(IF($B$1:$B$20<>"",ROW($B$1:$B$20)),ROW(INDIRECT("1:"&COUNTA($B$1:$B$20)))),0)+1),ROWS($B$1:$B$20)+1)-SMALL(IF($B$1:$B$20<>"",ROW($B$1:$B$20)),MATCH(SMALL(IF($B$1:$B$20="LMS",ROW($B$1:$B$20)),ROW(INDIRECT("1:"&COUNTIF($B$1:$B$20,"LMS")))),SMALL(IF($B$1:$B$20<>"",ROW($B$1:$B$20)),ROW(INDIRECT("1:"&COUNTA($B$1:$B$20)))),0)))
    TRY THIS ARRAY FORMULA
    Attached Files Attached Files
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  7. #7
    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:

    Please Login or Register  to view this content.
    Then you can use wildcards in the FindText

    Examples:
    This formula counts areas that begin with "LFB" (notice the asterisk after LFR)
    Please Login or Register  to view this content.
    and this one counts areas that contain "LFB"
    Please Login or Register  to view this content.
    Does that help?

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

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

    Similar to Jon's,
    Insert a row before first data,
    In C2 copied down
    =IF(ISTEXT(B2), LEFT(B2,3), C1)

    Then in B22 for example
    =COUNTIF(C2:C21, "LFB")
    You can hide Column C.
    Attached Files Attached Files
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  9. #9
    Registered User
    Join Date
    07-26-2012
    Location
    Tetbury, England
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    73

    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!

  10. #10
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

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

    Is post 6 working?

+ 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