Merge Cells/Rows (Revisited)

dfolzenlogen

New Member
Joined
Oct 18, 2009
Messages
36
I am trying to merge cells from several rows similar cobbling together code from the response from Michal M to the post of Robert Dino on June 25, 2017. See link to post below:

https://www.mrexcel.com/forum/excel...hese-cells-quickly.html?highlight=Merge+Cells

In Robert Dino’s example, a pdf bank statement file when converted to Excel split the entries in the description column to multiple cells. He wanted a VBA macro solution to merge the data in the multiple vertical description cells to the 1st one so all data (DATE-DESCRIPTION-WITHDRAWAL/DEPOSIT) would be in a single row so he could import into his accounting software.

I want to do something similar but I have entries in several columns where the text is split to multiple cells. I tweaked Michael M’s code to read as follows:

Code:
Sub CombineCellsSplitFromRows()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
For r = lr To 2 Step -1
    If Range("A" & r).Value = "" Then
      Range("D" & r - 1).Value = Range("D" & r - 1).Value & " " & Chr(10) & Range("D" & r).Value
      Range("E" & r - 1).Value = Range("E" & r - 1).Value & " " & Chr(10) & Range("E" & r).Value
      Range("F" & r - 1).Value = Range("F" & r - 1).Value & " " & Chr(10) & Range("F" & r).Value
      Range("G" & r - 1).Value = Range("G" & r - 1).Value & " " & Chr(10) & Range("G" & r).Value
      Range("H" & r - 1).Value = Range("H" & r - 1).Value & " " & Chr(10) & Range("H" & r).Value
      Range("I" & r - 1).Value = Range("I" & r - 1).Value & " " & Chr(10) & Range("I" & r).Value
      Range("J" & r - 1).Value = Range("J" & r - 1).Value & " " & Chr(10) & Range("J" & r).Value
      Range("K" & r - 1).Value = Range("K" & r - 1).Value & " " & Chr(10) & Range("K" & r).Value
      Range("L" & r - 1).Value = Range("L" & r - 1).Value & " " & Chr(10) & Range("L" & r).Value
      Range("M" & r - 1).Value = Range("M" & r - 1).Value & "; " & Range("M" & r).Value
      Range("N" & r - 1).Value = Range("N" & r - 1).Value & "; " & Range("N" & r).Value
      Range("O" & r - 1).Value = Range("O" & r - 1).Value & " " & Chr(10) & Range("O" & r).Value
      Range("R" & r - 1).Value = Range("R" & r - 1).Value & " " & Chr(10) & Range("R" & r).Value
      Range("S" & r - 1).Value = Range("S" & r - 1).Value & " " & Chr(10) & Range("S" & r).Value
      Rows(r).Delete
    End If
Next r
End Sub


PROBLEM: The code works EXCEPT for the last record containing a group of split cells. Can someone give me some advice as to how to have the code take that one “last step” through the data?

Thanks in advance.
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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