Forum

Mouse left click on...
 
Notifications
Clear all

Mouse left click on a shape should select the cell underneath the cursor

8 Posts
3 Users
0 Reactions
270 Views
(@sduraivel)
Posts: 4
Active Member
Topic starter
 

Can anyone help me with this?

I have a big shape object embedded in my worksheet, which covers many cells below it. The shape has been filled with color and its transparency has been set to 75%.

I want to write an even procedure for mouse left click (if not possible double click). i.e., if I double click within any specific point of the shape, then the system should select the exact cell reference and return it instead of choosing the shape object. Further, it should choose the precise cell right below the mouse click.

Thanks in advance.

 
Posted : 13/02/2020 8:25 am
(@debaser)
Posts: 837
Member Moderator
 

Unfortunately, the Window.RangeFromPoint method seems to return the shape rather than the range underneath but if you can work with a slightly hacky workaround, you can do it by assigning this ShapeClick macro to the shape, which hides the shape temporarily then schedules a routine to run immediately that can affect the correct range and re-show the shape:

 

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim sh As Shape
Sub ShapeClick()
Set sh = ActiveSheet.Shapes(Application.Caller)
sh.Visible = False

Application.OnTime Now(), "getrange"
End Sub
Sub GetRange()

Dim cursorWhere As POINTAPI
Dim selected As Object
If GetCursorPos(cursorWhere) <> 0 Then
DoEvents
Set selected = ActiveWindow.RangeFromPoint(cursorWhere.x, cursorWhere.y)
If TypeName(selected) = "Range" Then selected.Interior.Color = vbRed
sh.Visible = True
End If
End Sub

 
Posted : 13/02/2020 9:54 am
(@sduraivel)
Posts: 4
Active Member
Topic starter
 

Thank you very much Velouria. I will try. I never wrote user32 type functions... hope i can added in VBA moudule...

 
Posted : 13/02/2020 12:36 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

I have to ask, why have you got a shape covering the sheet?

Phil

 
Posted : 13/02/2020 9:11 pm
(@sduraivel)
Posts: 4
Active Member
Topic starter
 

Hi Phil

We have a BBS system wherein several shape objects have to be embedded in one or multiple cells. if it is covering a single cell, I thought of writing cell value as the name of the shape and accordingly choose the right formula and process accordingly. However, if the shape covers multiple cells there comes a challenge! Hence, if I have this solution then whether a single cell or multiple cells I can apply based on mouse click.

This requirement just came from our team and I still struggle to get the logic to start with the development....

when I have seen the cursor's column and row highlight solution provided in this site, I have seen a comment that does not fill the shape as you cannot select the cell below. I wonder if you have any solution to overcome so that I can use similar logic for my requirement.

Note: By the way, your VBA solution for cursor highlights is very good using shape. I also found a software called Kutools which is not using shapes not using a conditional format, appears like a cell format but while not disturbing original cell formats it also works even on a protected sheet with an unknown password... I am totally clueless about how they could have developed!

Thanks

 
Posted : 14/02/2020 1:03 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi,

You're using a Bulletin Board System?  In Excel?

Without seeing your workbook I can't really picture what it is you are trying to do.  I don't understand what its purpose is.

Phil

 
Posted : 14/02/2020 6:43 am
(@sduraivel)
Posts: 4
Active Member
Topic starter
 

Hi Phil

As I mentioned, I yet to start this development. Meanwhile, I got some glimmer of hope at the below site...will look into it.

https://stackoverflow.com/questions/40019337/how-to-select-cell-on-the-back-of-a-shape-object-click-through-that-shape/60205296#60205296

Thanks,

regards

Duraivel S

 
Posted : 16/02/2020 1:27 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Duraivel,

I like to make things as simple as possible.  I've often found that 'requirements' for a job are actually focussed on how to do something rather than the end result. 

So by saying something must be done in a particular way, rather than saying this is the result we want, the poor old developer (you and me) end up jumping through very complicated programming hoops to deliver what the 'requirements' asked for 🙂

Anyway, best of luck with the project.

Phil

 
Posted : 16/02/2020 1:44 am
Share: