Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default Change color of specific text piece

Any idea of a suitable piece of code to convert the fonts' color of ONLY the
WORD "people", in the CURRENT SELECTION?

In other words, instead of hitting F2 a hundred times, placing the cursor to
the specific piece of text everytime, selecting it, and changing it to red
(for example), and then again moving to the other cell, there should be a
single code to carryout the exercise.

--
Thanx in advance,
Best Regards,

Faraz
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Change color of specific text piece

Hi Faraz

Try the below macro which works on the current selection


Sub FindAndColorCharacterWithinCell()
Dim cell As Range, intPos as Integer
For Each cell In Selection
With cell
Do
intPos = InStr(intPos + 1, .Value, "people", vbTextCompare)
If intPos Then
..Characters(Start:=intPos, Length:=6).Font.FontStyle = "Bold"
..Characters(Start:=intPos, Length:=6).Font.ColorIndex = 3
End If
Loop Until intPos = 0
End With
Next
End Sub

--
Jacob


"Faraz A. Qureshi" wrote:

Any idea of a suitable piece of code to convert the fonts' color of ONLY the
WORD "people", in the CURRENT SELECTION?

In other words, instead of hitting F2 a hundred times, placing the cursor to
the specific piece of text everytime, selecting it, and changing it to red
(for example), and then again moving to the other cell, there should be a
single code to carryout the exercise.

--
Thanx in advance,
Best Regards,

Faraz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Change color of specific text piece

Here is a macro that should do what you want...

Sub PeopleColorer()
Dim Cell As Range, StartAt As Long
For Each Cell In Selection
StartAt = InStr(1, Cell.Value, "people", vbTextCompare)
Do While StartAt 0
Cell.Characters(StartAt, 6).Font.ColorIndex = 3
StartAt = InStr(StartAt + 1, Cell.Value, "people", vbTextCompare)
Loop
Next
End Sub

--
Rick (MVP - Excel)


"Faraz A. Qureshi" wrote in
message ...
Any idea of a suitable piece of code to convert the fonts' color of ONLY
the
WORD "people", in the CURRENT SELECTION?

In other words, instead of hitting F2 a hundred times, placing the cursor
to
the specific piece of text everytime, selecting it, and changing it to red
(for example), and then again moving to the other cell, there should be a
single code to carryout the exercise.

--
Thanx in advance,
Best Regards,

Faraz


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default Change color of specific text piece

XClent
--
Thanx in advance,
Best Regards,

Faraz


"Jacob Skaria" wrote:

Hi Faraz

Try the below macro which works on the current selection


Sub FindAndColorCharacterWithinCell()
Dim cell As Range, intPos as Integer
For Each cell In Selection
With cell
Do
intPos = InStr(intPos + 1, .Value, "people", vbTextCompare)
If intPos Then
.Characters(Start:=intPos, Length:=6).Font.FontStyle = "Bold"
.Characters(Start:=intPos, Length:=6).Font.ColorIndex = 3
End If
Loop Until intPos = 0
End With
Next
End Sub

--
Jacob


"Faraz A. Qureshi" wrote:

Any idea of a suitable piece of code to convert the fonts' color of ONLY the
WORD "people", in the CURRENT SELECTION?

In other words, instead of hitting F2 a hundred times, placing the cursor to
the specific piece of text everytime, selecting it, and changing it to red
(for example), and then again moving to the other cell, there should be a
single code to carryout the exercise.

--
Thanx in advance,
Best Regards,

Faraz

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default Change color of specific text piece

Thanx bro!
--
Best Regards,

Faraz


"Rick Rothstein" wrote:

Here is a macro that should do what you want...

Sub PeopleColorer()
Dim Cell As Range, StartAt As Long
For Each Cell In Selection
StartAt = InStr(1, Cell.Value, "people", vbTextCompare)
Do While StartAt 0
Cell.Characters(StartAt, 6).Font.ColorIndex = 3
StartAt = InStr(StartAt + 1, Cell.Value, "people", vbTextCompare)
Loop
Next
End Sub

--
Rick (MVP - Excel)


"Faraz A. Qureshi" wrote in
message ...
Any idea of a suitable piece of code to convert the fonts' color of ONLY
the
WORD "people", in the CURRENT SELECTION?

In other words, instead of hitting F2 a hundred times, placing the cursor
to
the specific piece of text everytime, selecting it, and changing it to red
(for example), and then again moving to the other cell, there should be a
single code to carryout the exercise.

--
Thanx in advance,
Best Regards,

Faraz


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change Font color specific text jlr Excel Discussion (Misc queries) 1 May 6th 10 08:19 PM
Change text color of specific date range by macro in Excel Morgan LeFay Excel Programming 1 August 3rd 06 07:51 PM
Change color of specific text within a cell? [email protected] Excel Programming 1 July 13th 06 05:28 PM
search a column for a specific piece of data using vba dave91 Excel Programming 1 July 23rd 05 05:56 PM
search column for a specific piece of data using vba dave91 Excel Programming 2 July 23rd 05 02:24 PM


All times are GMT +1. The time now is 04:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"