PDA

View Full Version : [SOLVED] Deleting an Entire Row



LordDragon
12-31-2015, 01:31 PM
Greetings,


I'm trying to provide the user a way to delete an entire row from the item lists.

I have the following code, but am getting an error on the line that actually says "Delete".



Function RemoveSelectionYes()
'Removes the entire row for the selected item.


With ActiveSheet
.Unprotect "P@s0n"
.ActiveCell.EntireRow.Delete
.Protect "P@s0n"
End With

End Function


In case you need (or want) the rest of the code:


Sub RemoveSelection(control As IRibbonControl)

With ActiveSheet
If Intersect(ActiveCell, .Columns(3)) Is Nothing Then Exit Sub
If Intersect(ActiveCell, .UsedRange) Is Nothing Then Exit Sub

Call RemoveSelectionMessage

End With
End Sub



Function RemoveSelectionMessage()
'Warns the user they are about to permanently delete something.


Dim Msg As String
Dim Title As String
Dim Config As Integer
Dim ExcelBox As Integer


Msg = "You are about to permanently delete this item from the list."
Msg = Msg & vbNewLine & vbNewLine
Msg = Msg & "Are you sure you want to continue?"
Title = "WARNING!!"
Config = vbYesNo + vbExclamation + vbDefaultButton1
ExcelBox = MsgBox(Msg, Config, Title)

'Remove the part if selection is Yes.
If ExcelBox = vbYes Then Call RemoveSelectionYes

'Cancel the proceedure if the selection is No.
If ExcelBox = vbNo Then Exit Function


End Function


I appreciate any help I can get.

I'm sure it's something simple that I'm just missing.:banghead:

SamT
12-31-2015, 02:33 PM
Try Selection instead of Active Cell

LordDragon
12-31-2015, 02:41 PM
I get a Run-time error '438' (I'll look that up).

Object doesn't support this property or method.

Then it highlights the Delete part.

Bob Phillips
12-31-2015, 04:12 PM
Remove the dot in front of Activecell. It is a self-contained object, not a worksheet property.

LordDragon
01-01-2016, 12:15 AM
Thanks xld.

It would figure it was that pesky little dot again.