I have a large and complex table in excel, some of the cells in the first row contains formulas including some array formulas.
Users can input data into rows 2 and below via forms to avoid overwriting the formulas, the formulas fill a number of the cells automatically based on lookups etc from the users data input.
Periodically I want to delete all the user data and only retain the first row.
I have tried a number of different methods but the only one which works is extremely slow:
A much faster method of deleting the entire table contents is
In order to use this method I must copy the content of row 1 so that it can be pasted back again after the deletion.
I have tried a variety of different solutions, none of which work well, the nearest I have doesn't preserve the formulas.
Any other ideas I could try ?
Thanks in advance.
Users can input data into rows 2 and below via forms to avoid overwriting the formulas, the formulas fill a number of the cells automatically based on lookups etc from the users data input.
Periodically I want to delete all the user data and only retain the first row.
I have tried a number of different methods but the only one which works is extremely slow:
VBA Code:
Dim oSheetName As Worksheet
Dim sTableName As String
sTableName = "MyTable"
Set oSheetName = Sheets("MySheetName")
FirstRecord = 2
LastRecord = loTable.DataBodyRange.Rows.Count
For i = LastRecord To FirstRecord Step -1
loTable.ListRows(i).Delete
Next
A much faster method of deleting the entire table contents is
VBA Code:
loTable.DataBodyRange.Rows.Delete
In order to use this method I must copy the content of row 1 so that it can be pasted back again after the deletion.
I have tried a variety of different solutions, none of which work well, the nearest I have doesn't preserve the formulas.
VBA Code:
Dim MyRow As Variant
MyRow = loTable.DataBodyRange.Rows(1)
loTable.DataBodyRange.Rows.Delete
loTable.ListRows.Add
loTable.ListRows(loTable.ListRows.Count).Range.Resize(UBound(MyRow, 1)).Value = MyRow 'Only pastes values, formulas are lost !!!
Any other ideas I could try ?
Thanks in advance.