View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default How to select a single word from a cell?

Sub Highlight_Word()
Dim rng As Range
Dim cell As Range
Dim start_str As Integer


myword = InputBox("Enter the search string ")

Mylen = Len(myword)
Set rng = Selection
For Each cell In rng
start_str = InStr(1, cell.Value, myword, vbTextCompare)
If start_str Then
cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next
End Sub

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"JLGWhiz" wrote:

Assume the phrase is in cell B2.

Sub sk()
extr = Mid(Range("B2").Value, InStr(Range("B2"), "like"), 4)
MsgBox extr
End Sub

Or since you know the phrase, you could simply count the characters,
including the spaces.

extr = Mid(Range("B2").Value, 3 , 4)


"Westman" wrote in message
...
Hi all,
How to select a single word from a cell in Excel 2007?

Example: I like to eat chicken rice at the restaurant.
The statement is placed in a single cell. So, if I highlight the "like"
word, how do I get it using vb codes? Thanks.

ps: I'm using VsTO, visual studio 2005, excel 2007.