SHape Ranges Not Performing 100%

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm working with this code:

Code:
Sub toggle()

    Dim myDocument As Worksheet
    Dim rtarget As Variant

    Set myDocument = Worksheets("Workorders")
    Set rtarget = myDocument.Shapes(Application.Caller)
    
    
    With rtarget
        If .Fill.ForeColor.RGB = RGB(255, 255, 255) Then 'OFF to ON
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
            MsgBox "Caller: " & rtarget.Name
        Else
            .Fill.ForeColor.RGB = RGB(255, 255, 255) 'ON to OFF
            MsgBox "OFF"
        End If
    End With

    If rtarget.Name = "CUEALL" Then
        myDocument.Shapes.Range(Array("CUEDR", "CUEDT", "CUEFR", "CUEFT", "CUECR", "CUECT")).Fill.ForeColor.RGB = RGB(255, 0, 0)
    ElseIf rtarget.Name = "CULALL" Then
        myDocument.Shapes.Range(Array("CULDR", "CULDT", "CULFR", "CULFT", "CULCR", "CULCT")).Fill.ForeColor.RGB = RGB(255, 0, 0)
    ElseIf rtarget.Name = "HPEALL" Then
        myDocument.Shapes.Range(Array("HPEDR", "HPEDT", "HPEFR", "HPEFT", "HPECR", "HPECT")).Fill.ForeColor.RGB = RGB(255, 0, 0)
    ElseIf rtarget.Name = "HPLALL" Then
        myDocument.Shapes.Range(Array("HPLDR", "HPLDT", "HPLFR", "HPLFT", "HPLCR", "HPLCT")).Fill.ForeColor.RGB = RGB(255, 0, 0)
    ElseIf rtarget.Name = "RPEALL" Then
        myDocument.Shapes.Range(Array("RPEDR", "RPEDT", "RPEFR", "RPEFT", "RPECR", "RPECT")).Fill.ForeColor.RGB = RGB(255, 0, 0)
    ElseIf rtarget.Name = "RPLALL" Then
        myDocument.Shapes.Range(Array("RPLDR", "RPLDT", "RPLFR", "RPLFT", "RPLCR", "RPLCT")).Fill.ForeColor.RGB = RGB(255, 0, 0)
    ElseIf rtarget.Name = "WPEALL" Then
        myDocument.Shapes.Range(Array("WPEDR", "WPEDT", "WPEFR", "WPEFT", "WPECR", "WPECT")).Fill.ForeColor.RGB = RGB(255, 0, 0)
    Else
        myDocument.Shapes.Range(Array("WPLDR", "WPLDT", "WPLFR", "WPLFT", "WPLCR", "WPLCT")).Fill.ForeColor.RGB = RGB(255, 0, 0)
    End If

End Sub

The least half of the routine, with all the If-Else If-End If are meant to toggle the shape's colour from the white "off" colour to the "on" red colour" when one of the "xxxALL" shapes is selected.

In a scenario, suppose the user clicks on the shape button for WPEALL. The msgbox dispalys "Caller: WPEALL", however, only 2 of the 6 shapes in the shape range change to red. This is consistant with other selections as well ... in no case do all six shapes in their associated range turn red ... only ever just two, 3 or 4 of them.

I've ensured that all the shape names match what is code.

I have a worksheet activate code that defaults all the shapes to "off" using the same shape ranges, and this doesn't appear to be failing.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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