VBA bug in delete row code (with buttons)

dannyok90

Board Regular
Joined
Aug 30, 2016
Messages
115
Hi all,


Im having some intermitant trouble with the followin code (line where i've put the arrow)


The code sometimes breaks here and i have to close the spreadsheet and reopen it.. it works fine after that.. until it does it again.


Any ideas? :)


Thanks,
Dan




Code:
Option Explicit
Sub deletebutton()
    ' RSE Controls
    Dim delrng As Range
    Dim rngOld As Range
    Dim msgRes As VbMsgBoxResult
    Dim BTN As Shape
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual
    Set rngOld = ActiveCell
    Set delrng = ActiveSheet.Shapes(Application.Caller).TopLeftCell.EntireRow
    msgRes = MsgBox("This action can't be undone." & vbNewLine & "Are you sure you want to proceed?", vbOKCancel, "Delete Row.")
    If msgRes = vbOK Then
    Sheet1.Unprotect Password:="rse1"
    For Each BTN In ActiveSheet.Shapes
    If Not Intersect(delrng, BTN.TopLeftCell) Is Nothing Then BTN.Delete        '<=================
Next
    delrng.Select
    delrng.Delete
    Sheet1.Protect Password:="rse1"
    End If
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
    
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,214,540
Messages
6,120,107
Members
448,945
Latest member
Vmanchoppy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top