+ Reply to Thread
Results 1 to 11 of 11

Need VBA script to merge adjacent cells

  1. #1
    Registered User
    Join Date
    02-16-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Need VBA script to merge adjacent cells

    Hello,

    I would appreciate help to merge a few cells.

    There can be anywhere between 2 and 5 identical adjacent ones on the same row, I would like the VBA script to merge all those identical ones and keep the text.

    Here is an example of the before and after:
    Excel.jpg

    Thanks for your help.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need VBA script to merge adjacent cells

    Does this help?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-16-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Re: Need VBA script to merge adjacent cells

    Thank you John for your help.

    The script appears to clear the replicate values, but does not merge the cells that used to contain the replicate values.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need VBA script to merge adjacent cells

    Can you attach a sample. Showing a before and after which depicts the result that you want?

  5. #5
    Registered User
    Join Date
    02-16-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Re: Need VBA script to merge adjacent cells

    Sure,

    Here is the simplified example:

    Excel example.xlsm

    Thanks

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need VBA script to merge adjacent cells

    Oops. Sorry, I completely misread. Will review further.

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need VBA script to merge adjacent cells

    Maybe:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-16-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Re: Need VBA script to merge adjacent cells

    Thank you very much, this works perfectly.

    I am embarrassed to ask, but I can't figure it out, in this code where should I specify the name of the sheet this should be run on? I am adding this to the end of another script and the active sheet at the end is not the one it should be run on.

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need VBA script to merge adjacent cells

    Maybe add:

    Please Login or Register  to view this content.
    I had assumed the activesheet at first.

  10. #10
    Registered User
    Join Date
    02-16-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Re: Need VBA script to merge adjacent cells

    Thanks again for all your help, all done.

    The funny thing is that I start with merged cells, but the script could not handle the rest without unmerging them and filling the info in each unmerged cell, so I needed to re-merge them at the end.

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need VBA script to merge adjacent cells

    You're welcome. Glad to help out and thanks for the feedback. If you feel your problem has been resolved, then please mark this 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)

Similar Threads

  1. merge If adjacent cells are the same
    By ratdogexcel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-26-2013, 11:58 AM
  2. Excel VB Script Required to Insert PDF objects, Merge Cells and Format
    By timepass111 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-17-2011, 07:29 PM
  3. Merge Cells based on an adjacent row of values
    By Metal Head in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2011, 09:55 AM
  4. merge & sort non-adjacent cells
    By BeatBama in forum Excel General
    Replies: 8
    Last Post: 01-12-2011, 02:11 PM
  5. How to merge date from adjacent cells inbetween current cells
    By hdawson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2009, 08:03 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