VBA: mouse events IN cell

NetFlash

New Member
Joined
Jul 26, 2011
Messages
14
<hr style="color:#FFFFFF; background-color:#FFFFFF" size="1"> Picture the following scenario.
In cell A2 i have the following Text:
The quick brown fox jumps over the lazy dog

When I highlight a portion of this text I need a VBA Function to display the length in cell B2.

For instance.
I select A2: The quick brown fox
Cell B2 displays: 19

What i've got so far is this but have no clue how to use mouse events to capture just the selected portion of the text.
I'm guessing the use of Range("").select

Code:
Function GetLength(StrName As String)      
     GetLength = Len(StrName) 
End Function
Any and all help is appreciated
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,773
Thinking out loud...

To highlight (select) part of a string, you'd have to be in edit mode on that cell. You can't run VBA code whilst Excel is in edit mode. As soon as you come out of edit mode, the highlighting disappears (the portion of the string is no longer selected).

Or have I completely missed the mark?

What you could do (Excel 2007+) is change that portion of the string in some way (make it bold or a different font colour) and then use the Worksheet_Change event to work out which bit is bold or red or whatever.
 

Forum statistics

Threads
1,082,017
Messages
5,362,695
Members
400,686
Latest member
Aakash

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top