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:
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.
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: