Unable to Merge Uneven Cells in Excel

jpmayekar

New Member
Joined
Oct 25, 2017
Messages
8
Hi,
I have a problem. I have around 300 Rows of data with uneven cells in different columns as below


ABDE
1x1Expected Output1x1 x2
x2
2y12y1 y2 y3
y2
y3
3z13z1
4u14u1 u2 u3 u4 u5
u2
u3
u4
u5

<tbody>
</tbody>

Columns A and B are input and Column C and D are Expected Output.

Please note Merging cells result in loss of Data. Welcome any suggestion on this and thanks before hand:eek::eek::eek::)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
This is done manually, with no VBA automation. It only works with text, not with formulas or numbers.

Widen column E so that it can contain the complete joined string. Select the cells you want to merge. From the Home tab, select Fill>> Justify.
 
Upvote 0
As long as you don't have a formulae in Col A, here is a VBA approach
Code:
Sub copytrans()

    Dim Cl As Range
    Dim arr As Variant
    
    For Each Cl In Columns(1).SpecialCells(xlBlanks).Areas
        arr = Cl.Offset(-1, 1).Resize(Cl.Rows.Count + 1)
        Cl.Offset(-1, 2).Value = Cl.Offset(-1).Value
        Cl.Offset(-1, 3).Resize(1) = Join(Application.Transpose(arr), " ")
    Next Cl

End Sub
 
Upvote 0
This is done manually, with no VBA automation. It only works with text, not with formulas or numbers.

Widen column E so that it can contain the complete joined string. Select the cells you want to merge. From the Home tab, select Fill>> Justify.

This does not work
 
Upvote 0
For future reference, it makes life a lot simpler & easier, if you tell us the correct layout of your data.
This works with your test file
Code:
Sub copytrans()

    Dim Cl As Range
    Dim Arr As Variant
    Dim UsdRws As Long

    UsdRws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    Range("A1:B" & UsdRws).UnMerge
    For Each Cl In Range("A2:A" & UsdRws).SpecialCells(xlBlanks).Areas
        Arr = Cl.Offset(-1, 1).Resize(Cl.Rows.Count + 1)
        Cl.Offset(-1, 3).Resize(1).Value = Join(Application.Transpose(Arr), " ")
        Arr = Cl.Offset(-1, 2).Resize(Cl.Rows.Count + 1)
        Cl.Offset(-1, 4).Resize(1) = Join(Application.Transpose(Arr), " ")
    Next Cl

End Sub
 
Upvote 0
Excellent!!!!!!!!!!!!! (y)(y)o_O(y)
For future reference, it makes life a lot simpler & easier, if you tell us the correct layout of your data.
This works with your test file
Code:
Sub copytrans()

    Dim Cl As Range
    Dim Arr As Variant
    Dim UsdRws As Long

    UsdRws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    Range("A1:B" & UsdRws).UnMerge
    For Each Cl In Range("A2:A" & UsdRws).SpecialCells(xlBlanks).Areas
        Arr = Cl.Offset(-1, 1).Resize(Cl.Rows.Count + 1)
        Cl.Offset(-1, 3).Resize(1).Value = Join(Application.Transpose(Arr), " ")
        Arr = Cl.Offset(-1, 2).Resize(Cl.Rows.Count + 1)
        Cl.Offset(-1, 4).Resize(1) = Join(Application.Transpose(Arr), " ")
    Next Cl

End Sub
 
Upvote 0
HTML:
Sub ninerows()'' ninerows Macro'' Keyboard Shortcut: Ctrl+Shift+D'    ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-1],R[1]C[-1],R[2]C[-1],R[3]C[-1],R[4]C[-1],R[5]C[-1],R[6]C[-1],R[7]C[-1],R[8]C[-1])"   End Sub

I was working on this code. It worked
 
Upvote 0

Forum statistics

Threads
1,215,280
Messages
6,124,034
Members
449,139
Latest member
sramesh1024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top