Move shape back to previous position vba if outside defined range

Akanjana

Board Regular
Joined
Mar 22, 2020
Messages
104
Office Version
  1. 2016
Platform
  1. Windows
Q1. I have few rectangle shapes in cell "B3". and "B3" is label design area. if shape is moved outside cell "B3" then i need to show warning and move back selected shape to previous position from where it was moved. Therefore shape stay within design area and get printed properly. i tried following codes.
VBA Code:
Sub UndoShapesMoveOutside() 'if moved outside Design area
Dim shp As String, Adr As String

shp = Selection.Name
    Adr = "B3"

Set Rng = Range("B3")

If ActiveSheet.Shapes(shp).Top <> Rng And ActiveSheet.Shapes(shp).Left <> Rng Then
        'EnableEvents = False
        '.Undo
        '.EnableEvents = True
        '.SendKeys ("^z")

        MsgBox "Textbox is outside Design Area"

    With ActiveSheet.Shapes(shp)
        .Top = Range(Adr).Top
        .Left = Range(Adr).Left

    End With

    End If

End Sub
Above codes are not working as per my requirement. kindly check.
Q2 . Additionally, how i can adjust zoom size of sheet based on on column and row with of cell "B3" in inches in page layout mode with vba ?
Thank you
excel vba excel-vba
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Set Rng = Range("B3")
rrow = Rng.Row
rCol = Rng.Column
If ActiveSheet.Shapes(shp).TopLeftCell.Row <> rrow Or ActiveSheet.Shapes(shp).TopLeftCell.Column <> rCol Then
MsgBox "outside cell"
Application.SendKeys ("^z")
End if
But SendKeys is not effective solution.
 
Upvote 0
While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Please supply all relevant link(s). Thanks
 
Upvote 0
While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Please supply all relevant link(s). Thanks

I posted it in excelforums.com. I was not knowing the rules. I will take care of it. can you please help with this.
 
Upvote 0
Please supply a link to the actual post.
Also you need to supply to ALL other sites where you have asked this question
 
Upvote 0
Ok, that's fine, but can you please update your other threads to include cross post details, where needed.
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,862
Members
452,676
Latest member
woodyp

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