Prevent shapes from being moved into certain cell

RemcoVBA

New Member
Joined
Sep 21, 2021
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
I've build a planboard and I'm using shapes to represent work packages.
Users can move around the shapes and below code would return the first and last cell the rectangle is placed in.

Now I want to prevent that the users can move the shapes to certains cells (or the other way around : make sure they will always put the rectangle in a certain range).
Is there a way to do this? I know that I can lock cells for inserting values but shapes seems to float over the cell.

Code:
Worksheets("Sheet 1").Range("A1").Value = Cells(Sheet1.Shapes("Rectangle 4").TopLeftCell.Row, Sheet1.Shapes("Rectangle 4").TopLeftCell.Column).Value
Worksheets("Sheet 1").Range("B1").Value = Cells(Sheet1.Shapes("Rectangle 4").BottomRightCell.Row - 1, Sheet1.Shapes("Rectangle 4").BottomRightCell.Column).Value
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
If your boundary range is, for example, Range(Cells(3, 3), Cells(20, 10)), then you might consider the following...

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Shapes("Rectangle 4")
    If .TopLeftCell.Row < 3 Or _
        .TopLeftCell.Column < 3 Or _
        .BottomRightCell.Row > 20 Or _
        .BottomRightCell.Column > 10 Then
        MsgBox "Out of bounds - please move the shape within range."
    End If
End With
End Sub

The code goes into the sheet module with the shapes.

If the rectangle is out of bounds, the user will receive the MsgBox prompt and will not be able to continue until the rectangle is moved within range.

Cheers,

Tony
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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