+ Reply to Thread
Results 1 to 6 of 6

How to get the number of rows or columns in a merged cell?

  1. #1
    Registered User
    Join Date
    12-01-2007
    Posts
    42

    How to get the number of rows or columns in a merged cell?

    Hello,

    I would like, with a function for instance, to get the number of rows and/or columns of a merged cell.
    For instance the name of my merged cell is "zaza" which is the cells A1 to D3 merged.
    "zaza" represents a merged cell with 3 rows and 4 columns. How to get these noumbers?

    Thanks.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: How to get the number of rows or columns in a merged cell?

    Did you name the range before or after you merged it ?

    If you named A1:D3 "zaza" and then subsequently merged the cells you can obtain the Rows/Columns using:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-01-2007
    Posts
    42

    Re: How to get the number of rows or columns in a merged cell?

    Hello DonkeyOte,

    The cell is named BEFORE.

  4. #4
    Registered User
    Join Date
    12-01-2007
    Posts
    42

    Re: How to get the number of rows or columns in a merged cell?

    Unfortunately it does not work. If zaza is (A1:D5).Merge, I always get 1...

    I would like:

    - verticaly (Rows): 5
    - horizontaly (Columns): 4

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: How to get the number of rows or columns in a merged cell?

    I don't think the range is named before you merge it that or either only the top left most cell of the range is named before merge - in either case you would get 1 as you outline.

    Merged cells do not work quite as people think - in reality the content of the merged area generally resides only in the top left most cell of the merged area.

    Please Login or Register  to view this content.
    will return value of zaza

    Please Login or Register  to view this content.
    will return nothing (blank/0) assuming it (A2) was empty prior to being merged.. although part of the merged area it is itself devoid of content - the content exists only in A1

    So ... my point was basically... if you had A1:D5 highlighted, then named, then merged - ROWS and COLUMNS would return the expected values.

    I'm not sure, off hand, is there is a native function you can use to determine the address of a merged area if the area is named after the merge or only the top left cell is named before merge ... I think you would be looking at VBA
    (things are also complicated of course by the fact that any given name can cover multiple non-contiguous areas - merged or not)

    Please Login or Register  to view this content.
    stored in a Module in VBE, called from a cell along the lines of:

    Please Login or Register  to view this content.
    where the first parameter is the range of interest and the second (0,1) stipulates whether you're returning Rows (0) or Columns (1) ... for a non-contiguous range like A6:C7, B12:C13 the above would return 4 for rows and 3 for columns.

    I'm sure there are far more elegant and robust methods out there to do this kind of analysis though.

    EDIT: code corrected - missing a release of rngRC in the Loop
    Last edited by DonkeyOte; 01-22-2010 at 07:06 AM.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: How to get the number of rows or columns in a merged cell?

    Just to wrap this up...

    the UDF can be used with Merged Areas & Non-Merged Areas, Names and non-Names, Contiguous and non-Contiguous ranges...
    (obviously use with unnamed contiguous ranges would be a little pointless...)

    it should return the count of unique rows / columns contained within the specified range.

    Examples:

    Please Login or Register  to view this content.
    Note that if any of the above ranges were themselves part of a merged area the merge area range would supercede, eg: J2 was merged as J2:L2 then:

    Please Login or Register  to view this content.
    obviously you could add a further toggle re: unique/non-unique if so desired.
    Last edited by DonkeyOte; 01-22-2010 at 07:58 AM. Reason: J2 was referened as J2:J2 which was a bit pointless...

+ 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