Adding 2 ActiveX buttons throws errors ?

gray_b

New Member
Joined
Apr 17, 2019
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Adding 2 ActiveX buttons throws errors ? Any ideas on the below images, and the error message please.

In changing the code in Macro1 to just show the Msg box. Selecting 'Clear Data' button (commandbutton1) It works OK. The 2 buttons follow where I curser click on screen.

But in changing that code to just 2 line of clearing data, I get this error shown in first image.


Screenshot 2023-12-20 090042.png



Screenshot 2023-12-20 090116.png
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try changing your Macro1 sub to:
VBA Code:
Sub Macro1()
    Application.EnableEvents = False
    Range("A:F").EntireColumn.ClearContents
    Application.EnableEvents = True
End Sub
The above will stop the clearcontents code from firing the below selection change code.

With your selection change code:
You can make it so that the code will only fire if one cell is selected:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
   
    'Your code here
End Sub

Taking that further you can restrict the running of the code to only one cell AND only if within a specific range:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
   
    If Not Intersect(Target, Range("A1:A22")) Is Nothing Then
        'Your code here
    End If
End Sub
 
Upvote 0
Hi - I have incorporated your code snippets 1 and 2, and all is working OK.

I do not pretend to understand the coding for it. I must read up about it.

My next step is to try and add a 'text box' with some information on how to gather the data from another program, before pasting them here.
I have tried activeX 'label' and 'text', but neither are any good at showing just 4 lines of text. The text box to follow the commandbuttons

Again I at a loss on how to do this.
 
Upvote 0

Forum statistics

Threads
1,216,029
Messages
6,128,404
Members
449,448
Latest member
Andrew Slatter

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