Buttons on top of other

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello Experts
I have this excel sheet which has 2 macro buttons one below the other namely Button1 and Button2. I want to place the buttons one on top of other with the help of a code. When I press Button1 automatically Button2 must be on the top and vice versa. If the user presses the Button1 before Button2 then the code generates an error. To avoid this I want to try the above way.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
That seems pretty complex.
Why not just have a flag (some cell somewhere in your sheet) that gets updated when Button 1 is pushed.
Then, at the top of the code for Button 2, you could have it check that "flag", and if it has not been updated, it can return a Message Box telling them they need to click Button 1 first, and then exit the sub.
 
Upvote 0
Do you mean to add a message box in the beginning of the code. I think if the button which has run already goes below the next button to be run would be better.
 
Upvote 0
I don't mess around with moving around buttons myself. Never really found the need to do so.

What do each of the buttons do?
Do you really need both buttons, or could they be combined to one?

Its hard to make pertinent suggestions without really understanding the purpose/role of each button.
So any detail you can provide may be helpful.
 
Upvote 0
Query 3.xlsm
BCDEFH
1ENTER DATE
209-12-2021
3
Birthdays & Anniverseries
Cell Formulas
RangeFormula
D2D2=TODAY()


Query 3.xlsm
BCDEFH
1ENTER DATE
209-12-2021
3
Birthdays & Anniverseries
Cell Formulas
RangeFormula
D2D2=TODAY()


I had some help and done this before.
 
Upvote 0
One button is to GenerateXML of one particular data. The other is to clear all the data in the sheets where the workings are done, so that the next data can be posted and again GenerateXML.
Post #5 is not showing the buttons but there is a single button in the sheet. If I press once then the button on the back comes to the front and vice versa. This is how I want in my new project also
This is the code in the sheet
Sub HideButtons()

ActiveSheet.Shapes("btnFilter").Visible = True
ActiveSheet.Shapes("btnOriginal").Visible = False

End Sub
Sub UnHideButtons()

ActiveSheet.Shapes("btnFilter").Visible = False
ActiveSheet.Shapes("btnOriginal").Visible = True

End Sub
 
Last edited:
Upvote 0
Put a Form Control Button on the sheet with the text "Up Up And Away" (no double quotation marks)
Put these in a regular module

Code:
Sub Change_Button_Text()
    If ActiveSheet.Buttons(Application.Caller).Caption = "Up Up And Away" Then
        ActiveSheet.Buttons(Application.Caller).Caption = "Down Down And Back Again"
        Macro_One
            Else
        ActiveSheet.Buttons(Application.Caller).Caption = "Up Up And Away"
        Macro_Two
    End If
End Sub

Code:
Sub Macro_One()
MsgBox "Changed to ""Down Down And Back Again"""
End Sub

Code:
Sub Macro_Two()
MsgBox "Changed to ""Up Up And Away"""
End Sub

Assign the "Change_Button_Text" macro to the button.
 
Upvote 0
Put a Form Control Button on the sheet with the text "Up Up And Away" (no double quotation marks)
Put these in a regular module

Code:
Sub Change_Button_Text()
    If ActiveSheet.Buttons(Application.Caller).Caption = "Up Up And Away" Then
        ActiveSheet.Buttons(Application.Caller).Caption = "Down Down And Back Again"
        Macro_One
            Else
        ActiveSheet.Buttons(Application.Caller).Caption = "Up Up And Away"
        Macro_Two
    End If
End Sub

Code:
Sub Macro_One()
MsgBox "Changed to ""Down Down And Back Again"""
End Sub

Code:
Sub Macro_Two()
MsgBox "Changed to ""Up Up And Away"""
End Sub

Assign the "Change_Button_Text" macro to the button.
Sorry Lolivanes. It is a bit complicated for me. Up Up and Away & Down Down And Back Again. Should I replace it with the name of the macro. (GenerateXML & ClearData)? Should I create a new macro of the above or add it in the existing code..?
 
Upvote 0
Time to hit the sack. Will try to solve it tomorrow. Thanks Joe4. Thanks Jolivanes.
 
Upvote 0
All you have to do what I suggested and see what happens. I don't know if you want to have a result of toggling codes.
Click on the button and one macro is activated while the text on the button changes to what the next macro will do.
Click again and the next macro will run while it changes the text again for the first macro.

BTW, you don't need to quote whole posts. most of us know what we suggested. All it does is create extra clutter.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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