+ Reply to Thread
Results 1 to 4 of 4

Merging Cell contents accross multiple rows

  1. #1
    Registered User
    Join Date
    09-28-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Merging Cell contents accross multiple rows

    I am trying to write a macro that concatenates the content of an unknown number of rows in to a single cell and separates the values with a CHAR(10). The groups of data I want to concatenate are separated by a blank row so I imagine that the Macro will need to be terminated via a check for two blank rows on the trot or the presence of a terminating value (in my feeble attempts so far I have used the word 'end' as the terminator). Its complicated further by the fact that some of the cells that need to be merged contain date & time values so they will need to be converted to text.

    Below is the skeleton of my initial attempts at getting my head around the algorithm but the main function of actually concatenating the cells is missing.

    I have also attached an example worksheet that shows the original data and the desired output (ignore the cell merging, that’s just to make it easier to read).

    I hope this makes some kind of sense... Thanks in advance for your help :-)

    Stu

    Please Login or Register  to view this content.
    Attached Files Attached Files

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

    Re: Merging Cell contents accross multiple rows

    See if this works for you...

    Please Login or Register  to view this content.
    Goes without saying merging cells is generally a bad idea!

  3. #3
    Registered User
    Join Date
    09-28-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Merging Cell contents accross multiple rows

    Absolutley brilliant. I cant understand most of the code, i suspect it may invlove voodo, but thank you very much indeed.
    I take tyour point about merging cells, i have comented out the merge line in the code and it still works a treat.
    Thanks again!
    Stu

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

    Re: Merging Cell contents accross multiple rows

    I'm glad it worked for you.

    The code is not annotated so is perhaps confusing rather than being overly complicated.

    In essence the code works along the lines of:

    -- uses Special Cells to identify each "Block" of data in your overall range
    -- iterates each block one by one
    -- iterates each column within each block one by one
    -- in the case of Column B it writes the contents of the column back into each cell again but as literal text strings rather than as true datetime stamps (to preserve formatting)
    -- the contents of each column are then pushed into an Array
    -- once the Array has been populated with all of the columns values the column range itself is cleared and then merged
    -- post merge the Array contents are then joined together into one long string with Chr(10) splitting each entry and the results are written into the first cell.
    It could no doubt be improved upon...

    Please remember to mark your thread as solved.

+ 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