PDA

View Full Version : [SOLVED] VBA 101



K. Georgiadis
03-15-2005, 08:10 PM
In the following simple macro, what instruction needs to be added so that the rectangle is drawn with its top left corner at the intersect of row 6 and column D (or thereabouts)?



Sub MakeNewRectangle()
Dim mySheet As Worksheet
Dim myShape As Shape
Dim myCell As Range
Set mySheet = ActiveSheet
Set myShape = mySheet.Shapes.AddShape(msoShapeRectangle, 72, 36, 72, 36)
myShape.Fill.ForeColor.SchemeColor = 10
End Sub


I answered my own question:) :



Sub MakeNewRectangle()
Dim mySheet As Worksheet
Dim myShape As Shape
Dim myCell As Range
Set mySheet = ActiveSheet
Set myShape = mySheet.Shapes.AddShape(msoShapeRectangle, 110, 110, 72, 36)
myShape.Fill.ForeColor.SchemeColor = 10
End Sub

BlueCactus
03-15-2005, 09:02 PM
But you can do better:


Sub MakeNewRectangle()
Dim mySheet As Worksheet
Dim myShape As Shape
Dim myCell As Range
Set mySheet = ActiveSheet
Set myShape = mySheet.Shapes.AddShape(msoShapeRectangle, _
mySheet.Columns("D").Left, mySheet.Rows("6").Top, 72, 36)
myShape.Fill.ForeColor.SchemeColor = 10
End Sub

K. Georgiadis
03-15-2005, 09:13 PM
Thanks!!!