Nilz
11-13-2014, 01:52 AM
Hi guys,
I am aiming to delete rows on a table, but I only want to keep the first row in my range (and delete everything else > 1) I have obtained some code on the internet but still struggling to help make this work?
' Delete tablerowsMacro
Dim tbl As ListObject
Dim Rowz As Integer
Set tbl = ActiveWorkbook.Worksheets("Populated sheet").ListObjects("Table5")
Set Rowz = tbl.DataBodyRange.Rows.Count
With Table
If Rowz > 1 Then .DataBodyRange.Offset(1, 0).Resize(.DataBodyRange.Rows.Count - 1, .DataBodyRange.Columns.Count).Rows.Delete
End If
End With
End Sub
Much appreciated!
N
I am aiming to delete rows on a table, but I only want to keep the first row in my range (and delete everything else > 1) I have obtained some code on the internet but still struggling to help make this work?
' Delete tablerowsMacro
Dim tbl As ListObject
Dim Rowz As Integer
Set tbl = ActiveWorkbook.Worksheets("Populated sheet").ListObjects("Table5")
Set Rowz = tbl.DataBodyRange.Rows.Count
With Table
If Rowz > 1 Then .DataBodyRange.Offset(1, 0).Resize(.DataBodyRange.Rows.Count - 1, .DataBodyRange.Columns.Count).Rows.Delete
End If
End With
End Sub
Much appreciated!
N