Launch a macro when a shape is moved

LSA_1984

New Member
Joined
Aug 11, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,
Here my challenge:

I've placed 4 rectangles - one below each other (with a little bit of space inbetween). I've named them R1, R2, R3 and R4. There current position is
(...).Left = 60 (for all)
(...).Top = 60 (for R1), 80 (for R1), 100 (for R1) & 120 (for R1)

My goal is to be capable to re-order them by moving the shapes: if I click with my mouse on "R4" and move it up somewhere inbetween "R1" and "R2", I want (after releasing my mouse) to see "R1" staying at its first position, "R4" beeing at the second position (coordinates: .Left = 60 and .Top = 80), "R2" moving down to the 3rd position and "R3" moving down to the last position. New order beeing R1-R4-R2-R3.

My approach so far is to have two table: One providing the .Left and .Top coordinates for the 4 expected positions (reference table) and the other one gathering the .Left and .Top positions of the 4 rectangles. I can anytime (upon demand) check the real position of the 4 rectangles and decide, based on their real position, in which order I want to see them appearing in their respective positions. So if I move "R4" manually inbetween "R1" and "R2", my "real position table" will show that the .Top value for "R4" is now the second lowest => I can reorder the 4 rectangles as expected: "R1", "R4", "R2", "R3"

My problem: today i need to click on a buton to update the "real position table". I want the macro to start as soon as a position move has been detected.

Any suggestions? best practises?

Thank you

Laurent
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
the are several posts in this message board on this subject - Events for Shapes or something similar.
It is not naturally supported by VBA.

However check this link: Shape events in VBA
I have not yet tested it myself but it looks promissing.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top