Result of a cell in an active X button

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
379
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

Is it possible to put cell that is calculated as in an active X button and if so how can I accomplish this?

Thank you for your responce,

Romano
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
If you mean show the result of the calculation on the button's surface, the use something like this ...
VBA Code:
CommandButton1.Caption = ThisWorkbook.Worksheets("Sheet1").Range("A1").Value
 
Upvote 0
If you mean show the result of the calculation on the button's surface, the use something like this ...
VBA Code:
CommandButton1.Caption = ThisWorkbook.Worksheets("Sheet1").Range("A1").Value
Good afternoon.
Yes this is what I meant, now it needs to refresh automatically. Can this be done also?

Thank you for your time.

Tomano
 
Upvote 0
You could use the calculate event for that. How the code exactly would look like depends on where your command button is located and on which worksheet the intended text is stored.
Either way, I would use the event handler on workbook level for that. In case both button and text are on the same worksheet the code could look like this ...

To be pasted in the ThisWorkbook module:
VBA Code:
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    If Sh.Name = "Sheet1" Then
         Sh.OLEObjects("CommandButton1").Object.Caption = Sh.Range("A1").Value
    End If
End Sub


In case your button is located on a userform a valid reference to that userform is needed, so the code that launches such a form has to be written in a way it takes that into account. In such a case I suggest to write a custom userform property for that rather than getting direct access to a userform's control.
 
Upvote 0
Solution
You could use the calculate event for that. How the code exactly would look like depends on where your command button is located and on which worksheet the intended text is stored.
Either way, I would use the event handler on workbook level for that. In case both button and text are on the same worksheet the code could look like this ...

To be pasted in the ThisWorkbook module:
VBA Code:
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    If Sh.Name = "Sheet1" Then
         Sh.OLEObjects("CommandButton1").Object.Caption = Sh.Range("A1").Value
    End If
End Sub


In case your button is located on a userform a valid reference to that userform is needed, so the code that launches such a form has to be written in a way it takes that into account. In such a case I suggest to write a custom userform property for that rather than getting direct access to a userform's control.
Thank you for your reply. This is what I was looking for.

Romano
 
Upvote 0
You're welcome and thanks for letting me know.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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