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?
I'm working in Excel 2010.
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.