ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Highlighting individual words in a cell with VBA (https://www.excelbanter.com/excel-programming/289440-highlighting-individual-words-cell-vba.html)

Shatin

Highlighting individual words in a cell with VBA
 
I wonder if this could be done...

I have a file with a column whose cells are descriptions, each cell
with maybe 20 to 30 words. What I want to do is look for some words in
the column and highlight them. For example, there is this sentence in
one of the cells:

An apple a day keeps the doctor away.

I want to highlight NOT the whole sentence BUT ONLY the word "doctor"
in red. I have tried to do this by editing a recorded macro. The
result wasn't very successful. What I managed to do was to highlight
the words "An apple a day keeps the doctor" in red, in other words,
from the beginning of the sentence to the word itself. The task is
complicated by the fact that I might want to highlight multiple words
in the same sentence. For example, I might want to highlight both
"apple" and "doctor" in red.

Can the above been done?

Chip Pearson

Highlighting individual words in a cell with VBA
 
Shatin,

Use the Characters property of the cell to access the individual
characters of text. For example,

Range("A1").Characters(26, 6).Font.ColorIndex = 3


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Shatin" wrote in message
om...
I wonder if this could be done...

I have a file with a column whose cells are descriptions, each

cell
with maybe 20 to 30 words. What I want to do is look for some

words in
the column and highlight them. For example, there is this

sentence in
one of the cells:

An apple a day keeps the doctor away.

I want to highlight NOT the whole sentence BUT ONLY the word

"doctor"
in red. I have tried to do this by editing a recorded macro.

The
result wasn't very successful. What I managed to do was to

highlight
the words "An apple a day keeps the doctor" in red, in other

words,
from the beginning of the sentence to the word itself. The task

is
complicated by the fact that I might want to highlight multiple

words
in the same sentence. For example, I might want to highlight

both
"apple" and "doctor" in red.

Can the above been done?





All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com