+ Reply to Thread
Results 1 to 7 of 7

Count merged rows in first column

  1. #1
    Registered User
    Join Date
    07-30-2010
    Location
    Mumbai,india
    MS-Off Ver
    Excel 2003
    Posts
    21

    Count merged rows in first column

    Hi All,


    I want to count the number of merged visible rows (i.e) if four rows are merged then it should be count as 1, and if the count reaches 13, I have to insert a horizontal pagebreak automatically.

    Please note that some merged rows are hidden in my case, so it should count only the visible merged rows and give the count.

    Please help in VB code.


    Regards,
    vivek.

    Thanks in Advance.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Problem in counting the number of merged rows in first column

    VBA and merged cells really don't get on. The best advice I could give you would be not to use them.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    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
    48,455

    Re: Problem in counting the number of merged rows in first column

    If you merge every 4 cells in column A and then put some numbers in the merged cells (say 1 to 16), it will appear as though the number is at the bottom (depending on your formatting). However, it is actually in the first cell of each group of merged cells.

    Try this little example:

    Please Login or Register  to view this content.

    It's also interesting that, if I put an Autofilter on and filter numbers less than or equal to 13, I only get the cells with the numbers, not the merged cell block.

    However, there's a clue there. Try:

    Please Login or Register  to view this content.

    Just be wary of header rows confusing the count

    Regards

  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
    48,455

    Re: Problem in counting the number of merged rows in first column

    Oh, I should also have said, I avoid merged cells like the plague as they screw up alls sorts of things.

    People tend to use them when they're trying to make the worksheet look pretty and are trying to avoid repetition of part numbers, or whatever. I tend to use conditional formatting for that and it means I keep all the data I need and can, if I want, sort the data without it getting totally FUBAR'd

    Regards

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Problem in counting the number of merged rows in first column

    Select the range of cells to evaluate in the first column then run this macro:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    07-30-2010
    Location
    Mumbai,india
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: Problem in counting the number of merged rows in first column

    Thanks for helping me..

    I have selected a range only in first column....
    But still i am getting error in highlighted line...

    ActiveWindow.SelectedSheets.HPageBreaks.Add _
    Before:=RNG.Cells(MyRow)


    The error is

    Runtime error 1004

    This action exceeds the number of pagebreaks you can add manually add to a worksheet.


    Thanks

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Problem in counting the number of merged rows in first column

    Um...I'm not sure what you're asking. The error is telling you have reached your maximum pagebreaks. So, what next? A maximum is a maximum.

+ 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