dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,392
- Office Version
- 365
- 2016
- Platform
- Windows
I have a spreadsheet with a table that is used for storing quotes that has a delete all table lines button. My supervisor needs a way to undo or restore if the delete all lines button is clicked. The quote could be up to 100 pages long, so re-entering all that information is just not practical. Can someone give me some ideas on how I could achieve this please as I thought of possibly saving a copy of the file before the delete all lines code is run but there may be a better way of doing this?
Here is the delete all lines code:
Thanks,
Dave
Here is the delete all lines code:
Code:
Sub cmdDeleteAllQuoteLines()
'Deleting The Data In A Table
Dim tbl As ListObject
Dim cell As Range
Set tbl = Sheets("NPSS_quote_sheet").ListObjects("npss_quote")
'Delete all table rows except first row
With tbl.DataBodyRange
If .Rows.Count > 1 Then
.Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).Rows.Delete
End If
'Clear the contents, but not delete the formulas
For Each cell In tbl.ListRows(1).Range.Cells
If Not cell.HasFormula Then
cell.Value = ""
End If
Next
End With
With ThisWorkbook.Worksheets("NPSS_quote_sheet")
.ListObjects("npss_quote").DataBodyRange.Columns(13).Value = 1 - 0.1 * ActiveSheet.chkIncrease.Value
.Rows(11).Font.Bold = False
End With
'ListObjects("NPSS_quote").ListColumns("10%Increase").DataBodyRange.Value = "1"
End Sub
Thanks,
Dave