Why doesn't resizing a rectangle work in Excel?

Hi Experts!

This is probably a very easy fix but it is driving me nuts. I have some rectangles on the screen. I want to resize them. I recorded a macro that drags the top edge up and get this code:

    Selection.ShapeRange.ScaleHeight (200), msoFalse, msoScaleFromBottomRight

The problem is when I run the code it resizes downward. Is there a way to force VBA to resize my rectangle up (i.e., anchor the bottom so it doesn't move)?

Ed MatsuokaPartner/Senior IT SpecialistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Could you send a dummy?

EDIT Are you sure your Shape is upwards

Ejgil HedegaardCommented:
You increase the height 200 times.
Probably the rectangle hit the top of the sheet, and then it scales down to make the correct size.
Try setting the scale factor to something small, like 1.2, and see what happens.
Martin LissOlder than dirtCommented:
Try working with the Height rather than the ScaleHeight,

This will increase the height by a maximum of 200. In other words if there's room enough between the top of the shape and the top of the sheet, the shape will increase in height by 200, otherwise the height will be increased only by as much as it can be without moving the bottom.

Sub SetHeight()

Const HITE = 200

Application.ScreenUpdating = False
If Selection.Top - HITE < 0 Then
    Selection.HEIGHT = Selection.HEIGHT + Selection.Top
    Selection.Top = 0
    Selection.HEIGHT = Selection.HEIGHT + HITE
    Selection.Top = Selection.Top - HITE
End If

Application.ScreenUpdating = True
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Ed MatsuokaPartner/Senior IT SpecialistAuthor Commented:
Thanks for the quick replies. The "200" is my fault, I just chose a number out of my hat (I don't use the other word!) since there was an array there which would just confuse the issue.

Martin I will try your code this morning.
Ed MatsuokaPartner/Senior IT SpecialistAuthor Commented:
Hi Martin,

With a little tweaking your code did the trick. Thanks and have a great day!
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.