Merge cells in a column based on values in other columns

Chimeara

New Member
Joined
Jan 6, 2005
Messages
6
I have a spreadsheet with thousands of rows from bank statements. The description of some transactions have been split over 2 or 3 rows and I need to merge them into a single row. The XXXXXXXXX needs to merged into row above it. So any row with a value in the description column that is without a value in the balance column the value in the description column needs to be merged into the description cell in the row above it.
The result for the first row below should be:
02/08/2022Inward Remittance XXXXXXXXXXXX XXXXXXXXXXXX999,999,999.0009,999,999.000

Current sheet
DateDescriptionDebitCreditBalance
02/08/2022Inward Remittance999,999,999.0009,999,999.000
XXXXXXXXXXXX
XXXXXXXXXXXX
02/08/2022Online Acct to Acct transfer99,999.000999.000
03/08/2022Salary Received999.00099,999.000
05/08/2022Debit Card Purchase
Card number
9999999.000999,999,999.000
XXXXXXXXXXXX
XXXXXXXXXXXX
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try:
VBA Code:
Sub CombineData()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long, arr() As Variant, lRow As Long, x As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    v = Range("A2:A" & lRow).Resize(, 6).Value
    ReDim arr(1 To WorksheetFunction.CountA(Range("A2", Range("A" & Rows.Count).End(xlUp))), 1 To 6)
    For i = LBound(v) To UBound(v)
        If v(i, 6) <> "" Then
            x = x + 1
            arr(x, 1) = v(i, 1)
            arr(x, 2) = v(i, 2)
            arr(x, 3) = v(i, 3)
            arr(x, 4) = v(i, 4)
            arr(x, 5) = v(i, 5)
            arr(x, 6) = v(i, 6)
        Else
            arr(x, 2) = arr(x, 2) & " " & v(i, 2)
        End If
    Next i
    ActiveSheet.UsedRange.Offset(1).ClearContents
    Range("A2").Resize(x, 6) = arr
    Columns.AutoFit
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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