1

I have a code that inserts a shape in the cell.

Suppose I insert shape in cell A1 and would like to write in that cell "5".

After the shape is inserted, the cell on-mouse-over cannot be selected because the shape is overlapping with it. I can only select the shape. Or, if I make shape unselectable, I cannot select neither shape, nor cell.

In order to write "5" in A1, I have to select e.g. cell B1 and with keyboard arrow <- move to cell A1. Then it works.

Is it possible to insert shape that is not only unselectable, but also is completely ignored on-mouse-over? It means the shape should be some kind of "behind the cell", but still visible. So that when you select the cell with shape, the selection priority is 100% taken by the cell.

Set Shp = ActWS.Shapes.AddShape(msoShapeOval, _
   ActWS.Cells(rActPlan - 1, vReturnColumn).Left, _
   ActWS.Cells(rActPlan - 1, vReturnColumn).Top, _
   ActWS.Cells(rActPlan - 1, vReturnColumn).Width, _
   ActWS.Cells(rActPlan - 1, vReturnColumn).Height)
Shp.Fill.Visible = msoFalse
With Shp.Line
    .Visible = msoTrue
    .ForeColor.RGB = RGB(0, 255, 0)
    .Transparency = 0
    .Weight = 2.25
End With

2 Answers 2

0

In case you do only need to select specific cells, you can define the cells to be editable like below. Afterwards you protect the sheet and allow solely to select locked and/or unlocked cells. Do let me know if you require a programmatic solution to this as well.

enter image description here

enter image description here

1
  • Thanks for the reply, but I think we have a misunderstanding. I have re-written the question to make it more clear
    – Meursault
    Feb 5, 2016 at 12:00
0

To my knowledge, you cannot create a shape "behind" a cell. However, what you can do is trigger an event every time the shape is selected. This event can be set to select the cell behind the shape. One implementation of this can be found in this answer. (Additional knowledge here).

Add the following sub to your code:

Sub SelectCell(Sht As String, Address As String)
    ThisWorkbook.Sheets(Sht).Range(Address).Select
End Sub

This procedure will simply select a specified cell on a specified sheet. We can set a shape to run this macro using .OnAction. We just have to tell the shape to run the SelectCell macro with our desired parameters (Sheet name, and cell address). To pass the parameters of your specified cell to the shape add the following code: (I am assuming that ActWS is your active worksheet)

    Shp.OnAction = "'SelectCell" & Chr(34) & ActWS.Name _
        & Chr(34) & ", " & Chr(34) _
        & ActWS.Cells(rActPlan - 1, vReturnColumn).Address _
        & Chr(34) & "'"

Now every time you click the circle, the circle will click the cell behind the circle, effectively allowing you to bypass the circle selection.

One nice thing (in my opinion) about this method is that a right-click of the circle won't trigger the macro, so editing the shape remains relatively easy. One not-so-nice thing about this method is that the cell selection will not travel with the shape location (i.e. Create shape to select A1, move shape to B1, click shape, shape will select A1). So you'd have to recreate the shapes each time a structural change is made to the worksheet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.