• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA - Move shape based on another shape's location

cacos

Member
Hi everyone!

First of all, congrats on the new forum!

I'm having some trouble with the following: I'm trying to move a shape, based on another shape's location (Application.Caller). So that when I click on that shape, the other shape will move (called "mover", for example).

So I tried the following (didn't work):

Code:
Dim PTop As Integer
Dim PLeft As Integer
 
PTop = Sheet1.Shapes(Application.Caller).Top
PLeft = Sheet1.Shapes(Application.Caller).Left
 
Sheet1.Shapes("mover").Left = PLeft + 10
Sheet1.Shapes("mover").Top = PTop + 10

I tried with MsgBox, and it says PLeft and PTop are always 0, regardless the shape position.

Hope it makes sense.

Thanks!!
 
Hi Lucas ,

Please specify your requirement in some detail ; suppose there are two shapes on your worksheet , say S1 and S2 ; suppose their locations are L1 and L2.

If you click on S1 , what is supposed to happen ?

If you click on S2 , what is supposed to happen ?

Narayan
 
Hi Narayan, for example if you click on S1 (the application caller) S1's text will go into a cell.

And apart from that (and completely independent), I'd like to have S2 move to stay next to S1. So basically we have a shape S2 that moves and stays next to the any shape that you click on that has that code.
 
Hi Lucas ,

Things are still not clear :

1. How many shapes are present on the worksheet ?

2. How many of these shapes will have this procedure assigned to them ?

3. If we assume there are 3 shapes on the worksheet , and if we assume that only S1 has the macro assigned to it , then when S1 is clicked , what will decide whether S2 moves next to S1 or S3 moves next to S1 ? The situation becomes even more confusing when the macro is assigned to more than one shape.

Can you please give a more detailed explanation ?

Narayan
 
Ok let's assume there are 3 shapes, all of them have the same macro assigned, that's why I'm using the "Application.Caller".

By just clicking on any of those shapes, the shape called "S2" (the one that moves) should move next to the shape that was clicked.

Assume that that's all that happens. Any time you click on any of those 3 shapes, "S2" moves near them by "reading" their position.

Should I use a cell reference? Is there any way to avoid that?
 
Ok let's assume there are 3 shapes, all of them have the same macro assigned, that's why I'm using the "Application.Caller".

By just clicking on any of those shapes, the shape called "S2" (the one that moves) should move next to the shape that was clicked.

Assume that that's all that happens. Any time you click on any of those 3 shapes, "S2" moves near them by "reading" their position.

Should I use a cell reference? Is there any way to avoid that?
Hi Lucas ,

Your code works the way you want it to ; can you download this file and let me know ?

https://www.dropbox.com/s/9xlg2qt01uclhgl/Example_Lucas.xlsm

Narayan
 
Yes, you are definitely right. It works, I was putting it in the wrong end of an IF-ELSE logic.
Can't believe it.

Thanks for your help as always Narayank
 
Back
Top