msoShapeRectangle

  • Thread starter Thread starter Andrew B
  • Start date Start date
A

Andrew B

Hi

I am drawing a horizontal rectangle on the sheet in reference to cell "G27".
(Shr = Sheets("Reports"))



I would like the left edge of the rectangle to start in the centre of
the cell. How do I do this ? .left + ???


With Shr.[G27]

Shr.Shapes.AddShape(msoShapeRectangle, .Left + ???, .Top + .Height *
0.75, 60, .Height / 4).Select

End With


TIA

Andrew B
 
This worked ok for me:

Option Explicit
Sub testme()
Dim myCell As Range
Dim myRect As Rectangle

Set myCell = Worksheets("Reports").Range("G27")

With myCell
Set myRect = .Parent.Rectangles.Add _
(Top:=.Top, _
Left:=.Left + (.Width / 2), _
Width:=.Width / 2, _
Height:=.Height)
End With

End Sub

(I wasn't sure how wide you wanted, so I made it fit the cell.)

Andrew said:
Hi

I am drawing a horizontal rectangle on the sheet in reference to cell "G27".
(Shr = Sheets("Reports"))

I would like the left edge of the rectangle to start in the centre of
the cell. How do I do this ? .left + ???

With Shr.[G27]

Shr.Shapes.AddShape(msoShapeRectangle, .Left + ???, .Top + .Height *
0.75, 60, .Height / 4).Select

End With

TIA

Andrew B
 
Thanks Dave.
I discovered through trial and error that the cell width was 15, and so
got something to work with that - but your method is better.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top