Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50178

VBA for shapes

$
0
0
A spreadsheet has a selection of five countries on a map (shape on the spreadsheet.) On selection of a shape, data is calculated from inputs worksheet onto output worksheet.

I have a couple of queries :
1) where do the names "Rectangle" and "Freeform" come from as they are not defined anywhere.
2) also, what is the code referring to f.left, width etc doing?

Thanks in advance

Code:


Sub PopulateBoxes(display As Boolean)
Dim c As Variant
Dim f, r As Object
Dim i, j As Integer
Dim Groups() As String

Sheets("Display").Select
For Each r In ActiveSheet.Shapes()
    If Left(r.Name, 9) = "Rectangle" Then
        i = i + 1
        r.Select
        Selection.BringToFront
        If display Then
            Selection.Characters.Text = Range("AREAS_DISPLAY").Cells(i, 1).Value
        Else:
            Selection.Characters.Text = i
        End If
        For Each f In ActiveSheet.Shapes()
        If Left(f.Name, 8) = "Freeform" And f.Left < r.Left And f.Left + f.Width > r.Left + r.Width _
        And f.Top < r.Top And f.Top + f.Height > r.Top + r.Height Then
        r.Left = f.Left + (f.Width - r.Width) / 2
        End If
        Next f
    End If
Next r
Range("A1").Select
End Sub


Viewing all articles
Browse latest Browse all 50178

Trending Articles