VBA Code generates runtime error 1004: A table cannot overlap with another table

Maartenengels

New Member
Joined
Nov 9, 2015
Messages
24
Hi guys,

I'm working on my code and it gives me runtime error 1004 when I try to run it. However, I can't see how the table I'm trying to create is overlapping with another table as there shouldn't be one (by all I know of VBA). Can you guys take a look at it and help me with this?

Code:
Sub CopyFilteredTable()

Dim rng1    As Range
Dim WS      As Worksheet
Dim tbl     As ListObject
Dim rng2    As Range


Application.DisplayAlerts = False


ThisWorkbook.Sheets("Feedback").Delete


Application.DisplayAlerts = True


ThisWorkbook.Sheets.Add.Name = "Feedback"
ActiveSheet.Move After:=Sheets(ActiveWorkbook.Sheets.Count)


For Each Row In Range("SurveyData[#All]").Rows
    If Row.EntireRow.Hidden = False Then
        If rng1 Is Nothing Then Set rng1 = Row
        Set rng1 = Union(Row, rng1)
    End If
Next Row


Set WS = Sheets("Feedback")
ActiveSheet.Move After:=Sheets(ActiveWorkbook.Sheets.Count)


rng1.Copy Destination:=WS.Range("A1")
Worksheets("Feedback").Range("K:K").WrapText = True
WS.Select


    On Error Resume Next
        WS.ListObjects("Table10").Delete
    On Error GoTo 0
    
    Set rng2 = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
    
    Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, rng2, , xlYes)
    
        
    tbl.Name = "Table10"
    tbl.TableStyle = "TableStyleMedium2"


    ActiveWindow.Zoom = 80
    
    Columns("A:A").Select
    Selection.ColumnWidth = 8.71
    Range("B:B,C:C,D:D").Select
    Selection.ColumnWidth = 12.14
    Columns("E:E").Select
    Selection.ColumnWidth = 11.43
    Range("F:F,G:G,H:H,I:I,J:J").Select
    Selection.ColumnWidth = 12.14
    Columns("K:K").Select
    Selection.ColumnWidth = 162.14
 
    ActiveSheet.ListObjects("Table10").ShowTotals = True
    
    Range("Table10[[#Totals],[Leadership and Organisational Skills]]").Select
    ActiveSheet.ListObjects("Table10").ListColumns("Leadership and Organisational Skills").TotalsCalculation = xlTotalsCalculationAverage
        
    Range("Table10[[#Totals],[Communication Skills]]").Select
    ActiveSheet.ListObjects("Table10").ListColumns("Communication Skills").TotalsCalculation = xlTotalsCalculationAverage
        
    Range("Table10[[#Totals],[Enthusiasm and willingness to help]]").Select
    ActiveSheet.ListObjects("Table10").ListColumns("Enthusiasm and willingness to help").TotalsCalculation = xlTotalsCalculationAverage
        
    Range("Table10[[#Totals],[Commentary and local knowledge]]").Select
    ActiveSheet.ListObjects("Table10").ListColumns("Commentary and local knowledge").TotalsCalculation = xlTotalsCalculationAverage
        
    Range("Table10[[#Totals],[Environmental awareness]]").Select
    ActiveSheet.ListObjects("Table10").ListColumns("Environmental awareness").TotalsCalculation = xlTotalsCalculationAverage
        
    Range("Table10[[#Totals],[Leadership and Organisational Skills]:[Environmental awareness]]").Select
    Selection.NumberFormat = "0.0"
    Range("Table10").WrapText = True
    
    Range("Table10[[#Headers],[Response ID]]").Select


End Sub

I'm working in Excel 2010.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,472
Messages
6,125,011
Members
449,204
Latest member
tungnmqn90

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