Results 1 to 4 of 4

Macro merge cells separated by comma, ignore blank cells

Threaded View

lagiosman Macro merge cells separated... 01-15-2014, 09:44 PM
jmac1947 Re: Macro merge cells... 01-15-2014, 11:18 PM
lagiosman Re: Macro merge cells... 01-16-2014, 08:03 AM
danielasaadi Re: Macro merge cells... 01-22-2014, 04:49 PM
  1. #1
    Registered User
    Join Date
    07-28-2013
    Location
    Athens
    MS-Off Ver
    Excel 2010
    Posts
    55

    Wink Macro merge cells separated by comma, ignore blank cells

    Finally i have found a solution with this formula:
    =IF(A1=0;"";A1&",") & IF(B1=0;"";B1&",") & IF(C1=0;"";C1)

    Ok this is the new macro that works:
        Columns("AD:AD").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        
        Range("AD2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(RC[-10]=0,"""",RC[-10]&"","") & IF(RC[-9]=0,"""",RC[-9]&"","") & IF(RC[-8]=0,"""",RC[-8]&"","") & IF(RC[-7]=0,"""",RC[-7]&"","") & IF(RC[-6]=0,"""",RC[-6]&"","") & IF(RC[-5]=0,"""",RC[-5]&"","") & IF(RC[-4]=0,"""",RC[-4]&"","") & IF(RC[-3]=0,"""",RC[-3]&"","") & IF(RC[-2]=0,"""",RC[-2]&"","") & IF(RC[-1]=0,"""",RC[-1])"
        Selection.AutoFill Destination:=Range("AD2:AD" & Range("A" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
        Range("AD2:AD" & Range("A" & Rows.Count).End(xlUp).Row).Select
    
        Selection.Copy
        Range("AE2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
    
        Range("AD:AD,AC:AC,AB:AB,AA:AA,Z:Z,Y:Y,X:X,W:W,V:V,U:U,T:T").Select
        Selection.Delete Shift:=xlToLeft
    info
    This Macro Merge Columns T,U,V,W,X,Y,Z,AA,AB,AC into AD Column and separates values by comma and ignores blank cells. After that it copies the results into AE Column and deletes the unnecessary Columns. So when the macro executes completely you have all this Columns merged into T Column
    Heres an example:
    IMAGE_1 IMAGE_2 IMAGE_3 MERGED_IMAGES
    myimage1.jpg myimage2.jpg myimage3.jpg myimage1.jpg,myimage2.jpg,myimage3.jpg
    myimage1_b.jpg myimage2_b.jpg myimage3_b.jpg myimage1_b.jpg,myimage2_b.jpg,myimage3_b.jpg
    myimage1_c.jpg myimage2_c.jpg myimage3_c.jpg myimage1_c.jpg,myimage2_c.jpg,myimage3_c.jpg

    PS!!!

    I have found a second problem, after the macro executes i have found some cells with an unneeded comma in the end of the cell value.
    So i have create a second macro to fix that problem with the macro recorder and this formula
    =IF(RIGHT(J2;1)=",";LEFT(J2;LEN(J2)-1);J2)
    You can change the formula to whatever you want, eg if you want to remove the "w" character in the end of the value of A2 cell you can change the formulla like this:
    =IF(RIGHT(A2;1)="w";LEFT(A2;LEN(A2)-1);A2)
    Last edited by lagiosman; 01-26-2014 at 01:00 PM.
    ~Our technology has exceeded our humanity~

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro that can merge a column of cells into one cell separated by semi colon
    By glide2131 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-25-2013, 05:23 PM
  2. [SOLVED] Macro to match values in cells separated by semicolon and comma
    By Ale84 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2013, 11:00 PM
  3. Replies: 8
    Last Post: 01-29-2010, 09:31 AM
  4. [SOLVED] How do I merge the contents (separated by a comma) of 300+ cells?
    By elliott in forum Excel General
    Replies: 3
    Last Post: 05-10-2005, 04:06 PM
  5. Replies: 1
    Last Post: 02-07-2005, 02:06 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