VBA - Shape A position next to shape B position

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,519
Office Version
  1. 2016
Platform
  1. Windows
Hello Friends,

I have two shapes. On the left is "Record" & on the right is "Rectangle 32"

What I want is the position of the shape "Record" to be on the left of shape "Rectangle 32" just like below image
I know I can manually adjust the shape "Record" just to the left of the shape "Rectangle 32" but the problem is that, the contents of the shape "Record" keeps on changing hence the width also changes.

Also, If anyone can let me know how to fix a shape's left / right position to a cell

1642346599800.png
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
left of "record" = left of rectangle32 - width of "record" and trigger at the right moment, but all that isn't obvious
 
Upvote 0
Solution
How does the width of the shape "Record" change ? and how often ?

This is in the worksheet change event

VBA Code:
ActiveSheet.Shapes("Record").Width = Range("K4").Value

It happens very often & the result is like this

1642348553503.png
 
Upvote 0
left of "record" = left of rectangle32 - width of "record" and trigger at the right moment, but all that isn't obvious
Wow, That did the trick

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  
ActiveSheet.Shapes("Record").Width = Range("K4").Value

Dim sp As Object: Set sp = ActiveSheet.DrawingObjects("Record")
Dim sp1 As Object: Set sp1 = ActiveSheet.DrawingObjects("Rectangle 32")

   sp.AutoSize = msoAutoSizeTextToFitShape
   sp.Left = sp1.Left - sp.Width
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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