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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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