Issue with 'Left' in macro

  • Thread starter Linking to specific cells in pivot table
  • Start date
L

Linking to specific cells in pivot table

Hi - this is driving me crazy -- below is code to re-size an object and then
move it -- what seems to be happening is that the it is not being moved as
the code specifies. I have five other blocks of code for five other objects
-- the blocks of code are identical -- and the other five objects are being
moved as specified by the code. Any help is really appreciated!!

'After executing the below code, the object has a 'Left' position of 290 --
as the code specifies, it should be a different number than 290

Sub changepctg()

'M9 = 100
'M10 = 100
'F7 = 0.012
'AutoShape1 = a trapezoid from the "Autoshape" - "Flowchart" menu

Sheets("1st Level Graph (2)").Select

ActiveSheet.Shapes("AutoShape 1").Select
Selection.ShapeRange.Height = Range("M9").Value
Selection.ShapeRange.Width = Range("M10").Value * (1 +
(Range("F7").Value - 0.5))
ActiveSheet.Shapes("AutoShape 1").Select
Selection.ShapeRange.Top = ((Selection.ShapeRange.Top - 15) / 2) + 15
Selection.ShapeRange.Left = ((Selection.ShapeRange.Left - 290) / 2) + 290
 
K

K Dales

What is the original .Left value for the ShapeRange for your AutoShape 1?
Note that if it was already 290, the result would be 290. But I will
continue to look at the code to see if I can find any other issues.
 
K

K Dales

I duplicated your code with the same type of autoshape (trapezoid from
Autoshape flowchart) with the following results for the .Left property of the
ShapeRange (original value : result value):
230.25 : 260.25
570.75 : 430.5
290:290

So unless the original .Left is 290 (or very close) the code seems to move
it. One question did come to mind: Is this shape part of a group of shapes?
The ShapeRange refers to the entire group, so if you have grouped the
trapezoid with any other shapes you are setting the left edge of the group,
not the left edge of your trapezoid. That might explain the results you are
getting.
 
L

Linking to specific cells in pivot table

Hi K,

Thanks for looking into this! After looking reading your response, I looked
at my code closer and foud what the problem was -- the trapezoid was being
resized by shortening it from right to left -- the result being that the Left
position of the trapezoid was not changing (the other trapezoids I have in my
spreadsheet are oriented at different angles which leads to them not being
resized from right to left).

The fix is that I simply orient the trapezoid 180 degrees before being
resized (this results in the trapezoid being re-sized from left to right
which means the Left position changes). After the new Left position is set,
I just re-orient it to 0 degrees.

Thanks for your help!

Robert
 

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