VBA - Shapes - Changing references to VBA shapes and adding new VBA shapes

Hi All,
    I'm trying to figure out this VBA code and I don't understand what's going on.  It' is assigning colors based on numbers.  Here is a sample of the code:

Sub MPS_Click()

Dim column_offset As Integer


Application.ScreenUpdating = False
   
    'Loop through until last populated cell

    column_offset = Range("m50").Value
    
    Range("l50").Value = Range("k51").Offset(0, column_offset).Value
    
    
    With ActiveSheet.Shapes("MPS")
        If Range("k52").Offset(0, column_offset).Value >= 90 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("k52").Offset(0, column_offset).Value < 90 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("PCPMED")
        If Range("K53").Offset(0, column_offset).Value >= 0.8 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K53").Offset(0, column_offset).Value < 0.8 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("PCPPED")
        If Range("K54").Offset(0, column_offset).Value >= 0.7 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K54").Offset(0, column_offset).Value < 0.7 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("PCPOB")
        If Range("K55").Offset(0, column_offset).Value >= 0.7 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K55").Offset(0, column_offset).Value < 0.7 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("PDAPRIM")
        If Range("K57").Offset(0, column_offset).Value >= 0.8 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K57").Offset(0, column_offset).Value < 0.8 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("PDAOB")
        If Range("K58").Offset(0, column_offset).Value >= 0.8 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K58").Offset(0, column_offset).Value < 0.8 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("PDAPED")
        If Range("K59").Offset(0, column_offset).Value >= 0.8 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K59").Offset(0, column_offset).Value < 0.8 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("SPECACC")
        If Range("K60").Offset(0, column_offset).Value >= 19 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K60").Offset(0, column_offset).Value < 19 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
     With ActiveSheet.Shapes("RADACC")
        If Range("K61").Offset(0, column_offset).Value >= 4 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K61").Offset(0, column_offset).Value < 4 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("KPORG")
        If Range("K63").Offset(0, column_offset).Value >= 0.664 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K63").Offset(0, column_offset).Value < 0.664 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("DIANINE")
        If Range("K66").Offset(0, column_offset).Value >= 0.85 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K66").Offset(0, column_offset).Value < 0.85 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("DIAEIGHT")
        If Range("K67").Offset(0, column_offset).Value >= 0.73 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K67").Offset(0, column_offset).Value < 0.73 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
     With ActiveSheet.Shapes("HYPER")
        If Range("K68").Offset(0, column_offset).Value >= 0.87 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K68").Offset(0, column_offset).Value < 0.87 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
        End With
        With ActiveSheet.Shapes("COLO")
        If Range("K70").Offset(0, column_offset).Interior.Color = RGB(0, 176, 80) Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K70").Offset(0, column_offset).Interior.Color = RGB(255, 0, 0) Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
        End With
        With ActiveSheet.Shapes("BREAST")
        If Range("K71").Offset(0, column_offset).Interior.Color = RGB(0, 176, 80) Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K71").Offset(0, column_offset).Interior.Color = RGB(255, 0, 0) Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
        End With
         With ActiveSheet.Shapes("CERV")
        If Range("K72").Offset(0, column_offset).Interior.Color = RGB(0, 176, 80) Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K72").Offset(0, column_offset).Interior.Color = RGB(255, 0, 0) Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
        End With
    With ActiveSheet.Shapes("PDR")
        If Range("K74").Offset(0, column_offset).Value <= 221 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K74").Offset(0, column_offset).Value > 221 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
     With ActiveSheet.Shapes("HCAHPS")
        If Range("K75").Offset(0, column_offset).Value >= 79.9 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K75").Offset(0, column_offset).Value < 79.9 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("CSECT")
        If Range("K77").Offset(0, column_offset).Value <= 66 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K77").Offset(0, column_offset).Value > 66 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("NORMAL")
        If Range("K78").Offset(0, column_offset).Value <= 37 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K78").Offset(0, column_offset).Value > 37 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("HCAHPS2")
        If Range("K79").Offset(0, column_offset).Value >= 79 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K79").Offset(0, column_offset).Value < 79 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("ROOMS")
        If Range("K81").Offset(0, column_offset).Value >= 0.7 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K81").Offset(0, column_offset).Value < 0.7 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("2WEEKS")
        If Range("K82").Offset(0, column_offset).Value >= 0.9 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K82").Offset(0, column_offset).Value < 0.9 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("4WEEKS")
        If Range("K83").Offset(0, column_offset).Value >= 0.9 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K83").Offset(0, column_offset).Value < 0.9 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("OR")
        If Range("K84").Offset(0, column_offset).Value >= 0.1 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K84").Offset(0, column_offset).Value < 0.1 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("CODING")
        If Range("K92").Offset(0, column_offset).Interior.Color = RGB(0, 176, 80) Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K92").Offset(0, column_offset).Interior.Color = RGB(255, 0, 0) Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
        End With
    With ActiveSheet.Shapes("ATTEND")
        If Range("K94").Offset(0, column_offset).Value <= 6.5 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K94").Offset(0, column_offset).Value > 6.5 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("WPS")
        If Range("K95").Offset(0, column_offset).Value <= 3.3 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K95").Offset(0, column_offset).Value > 3.3 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("MEMBERS")
        If Range("Q96").Value >= 1 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("Q96").Value < 1 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    With ActiveSheet.Shapes("BUDGET")
        If Range("K97").Offset(0, column_offset).Value >= 0 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("K97").Offset(0, column_offset).Value < 0 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
    End With
    
Application.ScreenUpdating = True

'ActiveSheet.Range("d2").Activate
    
End Sub

Open in new window


So, essentially, each of these "shapes" point to a colored circle on a presentation layer.  I have a couple requests

1. How do I take the shape from the presentation layer and change which "shape" it refers to.  It seems like when I try to override it, it just goes back to the original shape name it is pointing to.  I have attached a screen shot of a sample of the shape ,the cell where the data is referencing, and the top left box (named range box) where you can see it associating the shape to that corresponding shape.  I want to be able to add new shapes to the VBA code as well as take an already existing circle on the presentation layer and point it to different "shapes" within the vba code.

Hope my request is not too confusing.

Thanks,
Andy
6-4-2015-9-04-28-AM.jpg
akatz66Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
You can 'rename' a shape in VBA.
thisShape.Name = "test123"

And the shapes are indepentent of the cells upon which they are placed as they can float over multiple.

but you can assign it to an object to make it possible to work on different shapes using a routine.

 
    
    Dim myShape As Shape
    
    Set myShape = ActiveSheet.Shapes("MPS")
    With myShape
        If Range("k52").Offset(0, column_offset).Value >= 90 Then
            .Fill.ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Range("k52").Offset(0, column_offset).Value < 90 Then
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
    
        End If
        .Name = "MPS123"
    End With
    
    Set myShape = ActiveSheet.Shapes.AddShape(Type:=msoShapeRectangle, Left:=50, Top:=50, Width:=100, Height:=200)
    myShape.Name = "test123"

Open in new window


new shapes can be created by using Copy or better AddShape,  setting the Top and Left properties. then create a name.
 
not sure it helps much.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.