ZOrder msoBringToFront Using Text in Command Button Combo Box

jbiehl

Board Regular
Joined
Jul 30, 2020
Messages
59
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon!
If I can't find a solution here, the code below is going to need to be duplicated for hundred of images, so I'm hopeful!
I have a combobox named CB_ST_STA. Each time that combo box is clicked, I need the chart and a slicer tied to the selection to be brought to the front. The chart will have the same name as the item in the combobox and the slicer will have that name followed by "_Overall".

The code I currently have is at the bottom, but I was hoping to have something that like this:
Private Sub CB_ST_sta_click()
If.Me.CB_ST_STA=Shapename then
ActiveSheet.Shapes(ShapeName that matches CB_ST.STA).ZOrder msoBringToFront
ActiveSheet.Shapes(ShapeName that matches CB_ST.STA & "_Overall").ZOrder msoBringToFront

VBA Code:
Private Sub CB_ST_sta_click()
If Me.CB_ST_STA = "RL.8.1" Then
ActiveSheet.Shapes("RL.8.1").ZOrder msoBringToFront
ActiveSheet.Shapes("RL.8.1_Overall").ZOrder msoBringToFront

Any help is appreciated!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
VBA Code:
Private Sub CB_ST_sta_click()
    With Me.CB_ST_STA
        ActiveSheet.Shapes(.Value).ZOrder msoBringToFront
        ActiveSheet.Shapes(.Value & "_Overall").ZOreder msoBringToFront
    End With
End Sub
 
Upvote 0
Awesome, thanks!
Is there a way to avoid the error message if a chart matching the selected item isn't there?

1599933057042.png
 
Upvote 0
Better yet, would it be possible to bring a certain shape the the front if the chart doesn't exist?
I could create a shape that says, "I'm sorry, there isn't a chart available for this standard." and another that says, "I'm sorry, there isn't a slicer available for this standard."
 
Upvote 0
You could use code like this, altering the oops as desired.
VBA Code:
Private Sub CB_ST_sta_click()
    On Error GoTo Oops
    With Me.CB_ST_STA
        ActiveSheet.Shapes(.Value).ZOrder msoBringToFront
        ActiveSheet.Shapes(.Value & "_Overall").ZOreder msoBringToFront
    End With
    On Error Goto 0
Exit Sub
Oops:
    ' MsgBox "not there"
    Beep
End Sub
 
Upvote 0
Solution
You could use code like this, altering the oops as desired.
VBA Code:
Private Sub CB_ST_sta_click()
    On Error GoTo Oops
    With Me.CB_ST_STA
        ActiveSheet.Shapes(.Value).ZOrder msoBringToFront
        ActiveSheet.Shapes(.Value & "_Overall").ZOreder msoBringToFront
    End With
    On Error Goto 0
Exit Sub
Oops:
    ' MsgBox "not there"
    Beep
End Sub
Thanks so much!
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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