ShelleyBelly
New Member
- Joined
- Mar 2, 2011
- Messages
- 44
Hi All,
I've the below code which does the trick but I get a runtime error 91 on the last line starting with "tbl" . I've used on error resume and it will happily work, but this is ofcourse not the answer. I believe the error lies in the fact that the data body range will be empty following the first if statement, but the first line starting with "tbl" doesn't throw an error. Any help would be much appreciated
I've the below code which does the trick but I get a runtime error 91 on the last line starting with "tbl" . I've used on error resume and it will happily work, but this is ofcourse not the answer. I believe the error lies in the fact that the data body range will be empty following the first if statement, but the first line starting with "tbl" doesn't throw an error. Any help would be much appreciated
Code:
Private Sub CombineTracks()
Application.ScreenUpdating = False
Dim Tbl As ListObject
Dim Mastertbl As ListObject
Dim ws As Worksheet
Set ws = Limbs
Set Mastertbl = Body.ListObjects("Body")
'Delete all table rows except first row
With Mastertbl.DataBodyRange
If .Rows.count > 1 Then
.Offset(1, 0).Resize(.Rows.count - 1, .Columns.count).Rows.Delete
End If
End With
'Loop through each table in the worksheet
For Each Tbl In ws.ListObjects
If Mastertbl.DataBodyRange.Rows.count = 1 Then
Tbl.DataBodyRange.Copy destination:=Mastertbl.DataBodyRange(1, 1)
Else
Tbl.DataBodyRange.Copy destination:=Mastertbl.DataBodyRange(Mastertbl.ListRows.count + 1, 1)
End If
Next Tbl
Application.ScreenUpdating = True
End Sub
Last edited: