+ Reply to Thread
Results 1 to 4 of 4

Merging Duplicate Cells

  1. #1
    Registered User
    Join Date
    02-17-2011
    Location
    Waterloo, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    5

    Merging Duplicate Cells

    Hello,

    I'm trying to write a Macro where a user selects a column, runs the macro, and it will scan downwards for duplicate row values and merge the cells.

    So if A1, A2, A3 were all 27, I want to merge the cells and center align vert/horizontal keeping one instance of the value 27 in Cell A(123), and it would continue scanning down the column merging duplicates until a row with no value occurs.

    As an aside, is there a good resource to quickly learn VBA syntax? I know Java/C++ but I'm just lost with VBA syntax (variable types / declaration, how to perform operations on cell ranges/selections, etc.).

    Thanks,
    Roger

    (Using Excel 2003 if that matters, I don't believe it has a Merge&Center function)
    Last edited by RogerDunham; 02-17-2011 at 11:51 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,986

    Re: Merging Duplicate Cells

    This Sub takes a column number as the argument and does what you describe starting on row 1. You will probably have to some wrapper code to execute it for your particular workbook. I don't know if you have a button, etc.

    Before I let you see the code, I will give you the standard warning against rampant merging of cells. It sometimes causes more problems than it solves. I can't give you specific advice without seeing your workbook.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    02-17-2011
    Location
    Waterloo, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Merging Duplicate Cells

    How is this Macro run? I've copied it into the VBA Editor, but it's not showing up in the ALT+F8 list of macros. Similarly pressing F5 (Run) brings up an empty list of macros. I've tried doing my own macros with Sub abc() End Sub and they show up, is it because this one has parameter col?

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,986

    Re: Merging Duplicate Cells

    It won't show up in the list because of the parameter. You can manage this a couple of ways, but this will probably be easiest for you:

    Add another sub like this:
    Please Login or Register  to view this content.
    It will run on whatever column is currently selected. MergeIt should show up in your macro list.

+ 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