SeagullWardy
New Member
- Joined
- Jul 20, 2018
- Messages
- 2
I am trying to get some code to work. What I am trying to do is write some code that when a user clicks on a cell it
The idea is that the user will be looking at summary sheet and can click on a cell to get some more detailed information.
At the moment I have the code working that creates the new sheet, does the query, posts the information, creates the button and assigns the macro to it. The problem is when I click the button I get an error message about the macro not being available in the worksheet. However, if I run the macro manually it does work so I am a little confused.
My code for creating the button and the deleting the sheet are as follows:
Anyone able to identify where I am going wrong?
Thanks
- Creates a new worksheet based on the value of the selected cell
- Queries a different worksheet in the same workbook and posts the required information in to the new worksheet
- It then adds a button and assigns it a macro
- This macro deletes the current worksheet
The idea is that the user will be looking at summary sheet and can click on a cell to get some more detailed information.
At the moment I have the code working that creates the new sheet, does the query, posts the information, creates the button and assigns the macro to it. The problem is when I click the button I get an error message about the macro not being available in the worksheet. However, if I run the macro manually it does work so I am a little confused.
My code for creating the button and the deleting the sheet are as follows:
Public Sub AddButton()
Application.ScreenUpdating = False
ActiveSheet.Buttons.Delete
ActiveSheet.Buttons.Add(Range("K1").Left, Range("K1").Top, 90, 25).Select
Selection.Name = "btnDeleteSheet"
Selection.OnAction = "DeleteCurrentSheet"
ActiveSheet.Shapes("btnDeleteSheet").Select
With Selection
.Characters.Text = "Close Sheet"
With .Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
End With
End With
ActiveSheet.Cells(1, 1).Select
End Sub
Public Sub DeleteCurrentSheet()
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
End Sub
Anyone able to identify where I am going wrong?
Thanks