• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Mouse left click on a shape should select the cell underneath the cursor|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Mouse left click on a shape should select the cell underneath the cursor|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosMouse left click on a shape should …
sp_PrintTopic sp_TopicIcon
Mouse left click on a shape should select the cell underneath the cursor
Avatar
Duraivel S

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
February 12, 2020
sp_UserOfflineSmall Offline
1
February 12, 2020 - 10:25 pm
sp_Permalink sp_Print

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.

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 689
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
2
February 12, 2020 - 11:54 pm
sp_Permalink sp_Print

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

Avatar
Duraivel S

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
February 12, 2020
sp_UserOfflineSmall Offline
3
February 13, 2020 - 2:36 am
sp_Permalink sp_Print

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

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
February 13, 2020 - 11:11 am
sp_Permalink sp_Print

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

Phil

Avatar
Duraivel S

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
February 12, 2020
sp_UserOfflineSmall Offline
5
February 13, 2020 - 3:03 pm
sp_Permalink sp_Print

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

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
6
February 13, 2020 - 8:43 pm
sp_Permalink sp_Print

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

Avatar
Duraivel S

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
February 12, 2020
sp_UserOfflineSmall Offline
7
February 15, 2020 - 3:27 pm
sp_Permalink sp_Print

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/ques.....6#60205296

Thanks,

regards

Duraivel S

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1550
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
8
February 15, 2020 - 3:44 pm
sp_Permalink sp_Print

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

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Riny van Eekelen, Lorna Henning
Guest(s) 8
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
Hans Hallebeek: 185
Newest Members:
Appiagyei Kofi Frimpong
Hilary Burchfield
Richie Wright
Adel Kock
Barbara Murray
Doug Milne
Siobhan Stringer
Rob Rooth
Tom Lewis
Jennifer Rodriguez-Avila
Forum Stats:
Groups: 3
Forums: 24
Topics: 6542
Posts: 28639

 

Member Stats:
Guest Posters: 49
Members: 32829
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.