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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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.
 
Upvote 0

Forum statistics

Threads
1,216,473
Messages
6,130,838
Members
449,597
Latest member
buikhanhsang

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