Toggle the text on a button at each press

IronM

New Member
Joined
Jan 20, 2022
Messages
15
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
So, this is a followup question of this thread.

I have now this code:
VBA Code:
Sub IronM()
   If Range("Plan").Column = 3 Then
      ThisWorkbook.Names("Plan").RefersTo = Range("Plan").Offset(, 1)
   Else
      ThisWorkbook.Names("Plan").RefersTo = Range("Plan").Offset(, -1)
   End If
End Sub

Is there a way to add to this code to a button so when I click once it will write Forecast on it and click second will show Planned and cycle between these 2 at each press (considering the default (column 3) is Planned?
Doesn't necessary needs to be a visual change of the design of the button but at least for the text to appear so I know on which column the name range moved to.

Thank you!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Is this a Form Control Button, or an ActiveX one?
 
Upvote 0
Is this a Form Control Button, or an ActiveX one?
I am using a Form Control Button but if it's better with ActiveX one, will use that too. The code you provided initially, I've added to a macro attached to the button. If there is a better way, I'm open to it.
 
Upvote 0
Forgot to ask, what is the name of the button?
 
Upvote 0
Ok, how about
VBA Code:
Sub IronM()
   If Range("Plan").Column = 3 Then
      ThisWorkbook.Names("Plan").RefersTo = Range("Plan").Offset(, 1)
   Else
      ThisWorkbook.Names("Plan").RefersTo = Range("Plan").Offset(, -1)
   End If
   With ActiveSheet.Shapes("FC_button").TextFrame.Characters
      .Text = IIf(.Text = "Planned", "Forecast", "Planned")
   End With
End Sub
 
Upvote 0
Solution
It appears they are inversed. And no matter if I replace in your code Planned with Forecast, they still appear wrong. Meaning that on column 3 I need it to be Planned and on 4 Forecat.
Does it have to do with the column not being 3 anymore? I changed it to 10 as I moved my data there...
 
Upvote 0
Will it be easier to use an ActiveX button? I also want to change the color of the button and apparently I cannon on a Form Control button.
 
Upvote 0
It appears they are inversed. And no matter if I replace in your code Planned with Forecast, they still appear wrong. Meaning that on column 3 I need it to be Planned and on 4 Forecat.
Does it have to do with the column not being 3 anymore? I changed it to 10 as I moved my data there...
Nevermind, I don't know what happened but now it works...

Many thanks!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,607
Members
449,037
Latest member
Arbind kumar

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