how do I use a macro to center a shape in a cell in excel

G

Guest

Just that! I have a macro that copies various data to create a formatted
sheet, and I want a shape to be centered vertically and horizontally within
the cell after the cell is resized. Problem at present is that the shape
retains its alignment with the top border of the cell when the cell is
resized. I want to be able to center it.
 
G

Guest

Got it!

Get the cell top and left properties; as well as the cell width and height
and the object width and height, then do this:


ActiveSheet.Shapes("Group 141").Select 'get the object
With Selection
.Left = Range("B23").Left + (Range("B23").Width - Selection.Width) / 2
.Top = Range("B23").Top + (Range("B23").Height - Selection.Height) / 2
End With
 

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

Top