Excel VBA Merge Cells for a Table run time error"1004"

Anonymous
2020-02-09T15:51:00+00:00

Table AccessDownload (A1:H172)  Merge cells where dates are the same and if description is closing Balance

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

65 additional answers

Sort by: Oldest
  1. Anonymous
    2020-02-12T14:12:30+00:00

    Here is the macro. File can be downloaded from https://1drv.ms/x/s!AldvjX7HG_m7gUYczQqCHoInx2p...

    Option Explicit
    
    Sub MergeCells()
        Dim LastRow As Long, i As Long, j As Long, k As Long
        Dim Ws As Worksheet
        
        Set Ws = ActiveSheet
        LastRow = Ws.Cells(Rows.Count, 1).End(xlUp).Row
        'If there is no data, leave Sub
        If LastRow <= 2 Then
            MsgBox "Sheet has no data"
            Exit Sub
        End If
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        j = 1
        For i = 3 To LastRow
            With Ws
                If .Cells(i, "A") = .Cells(i - 1, "A") Then
                    If .Cells(i, "B") = .Cells(i - 1, "B") And .Cells(i, "B") = "Closing Balance" Then
                        If j = 1 Then
                            k = i - 1
                        End If
                        j = j + 1
                    End If
                    Else
                    If j >= 2 Then
                        .Cells(k, "A").Resize(j).Merge
                        .Cells(k, "B").Resize(j).Merge
                        j = 1
                    End If
                End If
            End With
        Next i
    ExitSub:
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
    End Sub
    

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2020-02-12T14:49:11+00:00

    I inserted your macro in module 1 and I don't see the transfer in new table. The Final Copy Module 1- Copy.xlsm

    with the Module 1 is in one drive .

    https://onedrive.live.com/edit.aspx?cid=5b91884861232582&page=view&resid=5B91884861232582!975&parId=5B91884861232582!718&app=Excel

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2020-02-12T14:59:19+00:00

    I merged the cells in original table itself.

    Can you put the output in new table so that I can generate that output through VBA?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2020-02-12T15:21:39+00:00

    V.

    I included the Original Table without the Module.

    Can you insert the module with your code, and see if the transfer is working

    Thank you

    https://onedrive.live.com/edit.aspx?cid=5b91884861232582&page=view&resid=5B91884861232582!977&parId=5B91884861232582!718&app=Excel

    Was this answer helpful?

    0 comments No comments