Deleting Button using a Button (Code not working)

SledDave

New Member
Joined
Sep 14, 2016
Messages
11
Hey guys,

I have not been using VBA for very long so forgive me if this code is messy!

My excel sheet has a list of risks that are either applicable or not applicable.
Here is the code for Not Applicable:

VBA Code:
Sub Not_Applicable_1()
Dim btn As Button
  Application.ScreenUpdating = False
  Dim t As Range
    Set t = ActiveSheet.Range(Cells(18, 12), Cells(18, 12))
    Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
    With btn
      .OnAction = "Reverse1"
      .Caption = "Reverse"
      .Name = "ReverseButton1"
    End With
  Application.ScreenUpdating = True
 
Sheets("Risk Assessment").Range("B18:L18").Copy
ActiveSheet.Paste Destination:=Range("B81")
Sheets("Risk Assessment").Range("B81").EntireRow.Hidden = False
Sheets("Risk Assessment").Range("18:18").EntireRow.Hidden = True

Sheets("Pretend Other Sheet").Select
Range("B1:K1").Select
    Range("B1:K1").Select
    Selection.Clear
Sheets("Risk Assessment").Select

Range("A1").ClearOutline
End Sub

The button "ReverseButton1" that was just created needs to delete itself if pressed, along with unhiding and hiding rows:

VBA Code:
Sub Reverse1()

Rows(81).EntireRow.Hidden = True
Sheets("Risk Assessment").Range("18:18").EntireRow.Hidden = False
Sheets("Risk Assessment").Range("B81").EntireRow.Hidden = True
ActiveSheet.Shapes.Range(Array("ReverseButton1")).Select
    Selection.Delete

End Sub

But it just doesn't delete. I've tried a few different codes from other forums but nothing seems to work. A lot of issues with Objects not being defined.
PS I'm gonna have 80 of these buttons, so a total button wipe is a no go. As I know where the button would be, I've tried deleting buttons within a range, but I'm way over my head to be honest!

A little help would be amazing!

Cheers,

David
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
The idea of deleting buttons like that seems quite odd, but try
activesheet.oleobjects(""ReverseButton1").delete
 
Upvote 0
The idea of deleting buttons like that seems quite odd, but try
activesheet.oleobjects(""ReverseButton1").delete
Hey!

Thanks so much for taking the time to suggest a solution.

Unfortunately I get this error message with the above:

1676891762621.png
 
Upvote 0
VBA Code:
thisButton = Application.Caller
ActiveSheet.Shapes(thisButton).Delete
 
Upvote 0
You should always post what you tried. I have 1 too many leading quotes in that. Do you?
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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