Value of a cell being placed in a command button

Romano_odK

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

Is it possible to let a value be refresh in a command button and also have text next to it. So in this case I have a command button with the text "Stock <0" and underneath that text I would like to see the value from A4 in that button. Can this be done?

Thank you for your time.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Yes. You can do that with VBA. For example:

VBA Code:
Private Sub SetButtonCaptions()
CommandButton1.Caption = "Stock < 0" & Chr(10) & Sheet17.Range("I5").Value
End Sub
 
Upvote 0
Yes. You can do that with VBA. For example:

VBA Code:
Private Sub SetButtonCaptions()
CommandButton1.Caption = "Stock < 0" & Chr(10) & Sheet17.Range("I5").Value
End Sub
Good evening, thank you for your reply. It indeed works when I push the button. Can it als refresh when I hit the Refresh All button, which it doesn't do now?
 
Upvote 0
If you're referring to the Refresh All on the data ribbon then no, that won't work...but you could set the sub to the following:

VBA Code:
Private Sub worksheet_change(ByVal target As Range)
CommandButton1.Caption = "Stock < 0" & Chr(10) & Sheet17.Range("I5").Value
End Sub

This way, whenever any cell on the sheet is changed, it should refresh the button text.
 
Upvote 0
If you're referring to the Refresh All on the data ribbon then no, that won't work...but you could set the sub to the following:

VBA Code:
Private Sub worksheet_change(ByVal target As Range)
CommandButton1.Caption = "Stock < 0" & Chr(10) & Sheet17.Range("I5").Value
End Sub

This way, whenever any cell on the sheet is changed, it should refresh the button text.
Thank you that is exactly what I needed. Have a great weekend.
 
Upvote 0

Forum statistics

Threads
1,215,424
Messages
6,124,817
Members
449,190
Latest member
rscraig11

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