dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,375
- Office Version
- 365
- 2016
- Platform
- Windows
I have some code that is meant to delete a row and shift the cells up but it doesn't shift the cells up. If it is the last row in the table, I just want it to clear the contents.
Could someone help me adjust this code please so it also deletes a row and then shifts the rows up?
Code:
Sub DelSelectCostingRow()
ActiveSheet.Unprotect Password:="npssadmin"
Dim rng As Range
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("tblCosting")
On Error Resume Next
With Selection.Cells(1)
Set rng = Intersect(.EntireRow, ActiveCell.ListObject.DataBodyRange)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "Please select a cell within a row that you want to delete.", vbCritical
Else
ActiveCell.EntireRow.Select
If ActiveSheet.ListObjects("tblCosting").ListRows(1).Range.Select Then
tbl.DataBodyRange.Rows(1).SpecialCells(xlCellTypeConstants).ClearContents
Else
rng.Delete xlShiftUp
End If
End If
End With
'ListObjects("NPSS_quote").ListColumns("10%Increase").DataBodyRange.Value = "1"
Application.EnableEvents = True
'ActiveSheet.Protect Password:="npssadmin"
End Sub
Could someone help me adjust this code please so it also deletes a row and then shifts the rows up?