dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,352
- Office Version
- 365
- 2016
- Platform
- Windows
I have code to add n lines to my table but only have a button to delete one line at a time from the bottom. How do I change the sub DeleteRowBottom so you are asked, similar to the AddLines feature, how many lines to delete from the bottom of the table?
My AddLInes code is:
My DeleteRowBottom code is:
My AddLInes code is:
VBA Code:
Sub AddLines()
Application.EnableEvents = False
Dim ws As Worksheet, x As Long, tbl As ListObject, n As Long
On Error GoTo cancelled:
n = InputBox("How many lines would you like to add?")
Set ws = ActiveSheet
Set tbl = ws.ListObjects("CSS_quote")
For x = 1 To n
'add a row at the end of the table
tbl.ListRows.Add
Next x
Range("A:A").NumberFormat = "dd/mm/yyyy"
tbl.Range.Cells(tbl.ListRows.Count - n + 2, 1).Select
Application.EnableEvents = True
cancelled:
Exit Sub
End Sub
My DeleteRowBottom code is:
VBA Code:
Sub DeleteRowBottom()
Quoting.Unprotect Password:=ToUnlock
Dim ans As Long
On Error GoTo Halt
With ActiveSheet.ListObjects("CSS_quote").DataBodyRange
ans = .Rows.Count
If ans = 0 Then Exit Sub
If ans > 1 Then .Rows(ans).Delete
If ans = 1 Then .Rows(1).Cells.SpecialCells(xlCellTypeConstants).ClearContents
End With
'Selection.ListObject.ListRows(6).Delete
Call InsertFormulas
Halt:
On Error GoTo 0
'ActiveSheet.Protect Password:="CSSadmin"
Application.EnableEvents = True
End Sub