By: Lutfor Rahman Shimanto

In reply to Barry.

Hello Barry

Thanks for your compliment. Your appreciation means a lot to us. Thanks once again for sharing an exciting problem.

I have reviewed your requirements. You wanted to place small rectangles at each of the 12 positions on a clock face. Besides, each shape will be placed at an angle of 30 degrees; more than its neighbor. Don’t worry! I have come up with a sub-procedure and a user-defined function to fulfill your goal.

SOLUTION Overview:

Excel VBA Sub-procedure:

Sub PlaceRectanglesOnClockFace()

Dim centerX As Double
Dim centerY As Double
Dim radius As Double
Dim angleIncrement As Double
Dim angle As Double
Dim rectWidth As Double
Dim rectHeight As Double
Dim rect As Shape

centerX = 410
centerY = 110

radius = 100

rectWidth = 20
rectHeight = 10

angleIncrement = 30

angle = 0

For i = 1 To 12

Dim rectLeft As Double
Dim rectTop As Double
rectLeft = centerX + radius * Cos(DegreesToRadians(angle)) - rectWidth / 2
rectTop = centerY - radius * Sin(DegreesToRadians(angle)) - rectHeight / 2

Set rect = ActiveSheet.Shapes.AddShape(msoShapeRectangle, rectLeft, rectTop, rectWidth, rectHeight)
rect.Name = "Rect" & i

angle = angle + angleIncrement
Next i

End Sub

Function DegreesToRadians(degrees As Double) As Double
DegreesToRadians = degrees * WorksheetFunction.Pi / 180
End Function

I hope you have found the solution, you were looking for. I have attached the solution workbook as well; good luck.

DOWNLOAD SOLUTION WORKBOOK

Regards
Lutfor Rahman Shimanto
Excel & VBA Developer
ExcelDemy