Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 20
Default Multiple Formats per Cell

I'm trying to search for specific words in a MsExcel spreadsheet and format
them (using either a macro or formula) with multiple font colors

(e.g. search for "MY NAME IS TIM", and format it so the word "NAME" would be
BOLD RED, and all the other text would be black.

I'm basically trying to highlight individual words only, but not the entire
text string or the entire cell.

Is there a way to do this with either a formula or macro?
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Multiple Formats per Cell

Timo

Sub color_words()
Dim Cell As Range, tempR As Range, mystring As String, _
myword As String, rng As Range
mystring = InputBox("Enter the search string")
If mystring = "" Then Exit Sub
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = UCase(mystring) Then
If tempR Is Nothing Then
Set tempR = Cell
Else
Set tempR = Union(tempR, Cell)
End If
End If
Next Cell
If tempR Is Nothing Then
End
End If
tempR.Select
myword = InputBox("Enter the word to format ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
Set rng = Selection
rng.Cells.Font.ColorIndex = 0
For Each Cell In rng
start_str = InStr(Cell.Value, UCase(myword))
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End Sub


Gord Dibben MS Excel MVP

On Wed, 26 Nov 2008 12:06:01 -0800, Timo
wrote:

I'm trying to search for specific words in a MsExcel spreadsheet and format
them (using either a macro or formula) with multiple font colors

(e.g. search for "MY NAME IS TIM", and format it so the word "NAME" would be
BOLD RED, and all the other text would be black.

I'm basically trying to highlight individual words only, but not the entire
text string or the entire cell.

Is there a way to do this with either a formula or macro?


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 20
Default Multiple Formats per Cell

This is a good start. Thanks! However, the only problem I have with this
sub is that it prompts me for the text string. I'm searching through several
hundred different text strings and trying to highlight specific words if they
appear in a specific column (within an entire workbook, not just one
worksheet).
Any further advice?


"Gord Dibben" wrote:

Timo

Sub color_words()
Dim Cell As Range, tempR As Range, mystring As String, _
myword As String, rng As Range
mystring = InputBox("Enter the search string")
If mystring = "" Then Exit Sub
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = UCase(mystring) Then
If tempR Is Nothing Then
Set tempR = Cell
Else
Set tempR = Union(tempR, Cell)
End If
End If
Next Cell
If tempR Is Nothing Then
End
End If
tempR.Select
myword = InputBox("Enter the word to format ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
Set rng = Selection
rng.Cells.Font.ColorIndex = 0
For Each Cell In rng
start_str = InStr(Cell.Value, UCase(myword))
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End Sub


Gord Dibben MS Excel MVP

On Wed, 26 Nov 2008 12:06:01 -0800, Timo
wrote:

I'm trying to search for specific words in a MsExcel spreadsheet and format
them (using either a macro or formula) with multiple font colors

(e.g. search for "MY NAME IS TIM", and format it so the word "NAME" would be
BOLD RED, and all the other text would be black.

I'm basically trying to highlight individual words only, but not the entire
text string or the entire cell.

Is there a way to do this with either a formula or macro?



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Multiple Formats per Cell

So the text string doesn't matter?

Just the single word in any text string is what you're looking for?

Sub Highlight_Word()
Dim rng As Range
Dim ws As Worksheet
Dim Cell As Range
Dim myword As String
Dim start_str As Integer
Dim Mylen As Integer
Dim N As Single
myword = InputBox("Enter the word ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
For Each ws In ActiveWorkbook.Worksheets
ws.Select
With Selection
Set rng = Range(Range("A1"), Cells(Rows.Count, 1).End(xlUp))
For Each Cell In rng
Cell.Font.ColorIndex = 0
start_str = InStr(Cell.Value, myword)
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End With
Next ws
End Sub


Gord


On Tue, 2 Dec 2008 11:00:01 -0800, Timo
wrote:

This is a good start. Thanks! However, the only problem I have with this
sub is that it prompts me for the text string. I'm searching through several
hundred different text strings and trying to highlight specific words if they
appear in a specific column (within an entire workbook, not just one
worksheet).
Any further advice?


"Gord Dibben" wrote:

Timo

Sub color_words()
Dim Cell As Range, tempR As Range, mystring As String, _
myword As String, rng As Range
mystring = InputBox("Enter the search string")
If mystring = "" Then Exit Sub
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = UCase(mystring) Then
If tempR Is Nothing Then
Set tempR = Cell
Else
Set tempR = Union(tempR, Cell)
End If
End If
Next Cell
If tempR Is Nothing Then
End
End If
tempR.Select
myword = InputBox("Enter the word to format ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
Set rng = Selection
rng.Cells.Font.ColorIndex = 0
For Each Cell In rng
start_str = InStr(Cell.Value, UCase(myword))
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End Sub


Gord Dibben MS Excel MVP

On Wed, 26 Nov 2008 12:06:01 -0800, Timo
wrote:

I'm trying to search for specific words in a MsExcel spreadsheet and format
them (using either a macro or formula) with multiple font colors

(e.g. search for "MY NAME IS TIM", and format it so the word "NAME" would be
BOLD RED, and all the other text would be black.

I'm basically trying to highlight individual words only, but not the entire
text string or the entire cell.

Is there a way to do this with either a formula or macro?






  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 20
Default Multiple Formats per Cell

Close enough. I was able to modify your suggested macro to fit my needs. I
actually took out the InputBox so the macro would automatically check for the
words, and had to eliminate the code resetting the font color to 0, so I use
it to search for and modify several different words.

Thank you!!!!

"Gord Dibben" wrote:

So the text string doesn't matter?

Just the single word in any text string is what you're looking for?

Sub Highlight_Word()
Dim rng As Range
Dim ws As Worksheet
Dim Cell As Range
Dim myword As String
Dim start_str As Integer
Dim Mylen As Integer
Dim N As Single
myword = InputBox("Enter the word ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
For Each ws In ActiveWorkbook.Worksheets
ws.Select
With Selection
Set rng = Range(Range("A1"), Cells(Rows.Count, 1).End(xlUp))
For Each Cell In rng
Cell.Font.ColorIndex = 0
start_str = InStr(Cell.Value, myword)
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End With
Next ws
End Sub


Gord


On Tue, 2 Dec 2008 11:00:01 -0800, Timo
wrote:

This is a good start. Thanks! However, the only problem I have with this
sub is that it prompts me for the text string. I'm searching through several
hundred different text strings and trying to highlight specific words if they
appear in a specific column (within an entire workbook, not just one
worksheet).
Any further advice?


"Gord Dibben" wrote:

Timo

Sub color_words()
Dim Cell As Range, tempR As Range, mystring As String, _
myword As String, rng As Range
mystring = InputBox("Enter the search string")
If mystring = "" Then Exit Sub
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = UCase(mystring) Then
If tempR Is Nothing Then
Set tempR = Cell
Else
Set tempR = Union(tempR, Cell)
End If
End If
Next Cell
If tempR Is Nothing Then
End
End If
tempR.Select
myword = InputBox("Enter the word to format ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
Set rng = Selection
rng.Cells.Font.ColorIndex = 0
For Each Cell In rng
start_str = InStr(Cell.Value, UCase(myword))
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End Sub


Gord Dibben MS Excel MVP

On Wed, 26 Nov 2008 12:06:01 -0800, Timo
wrote:

I'm trying to search for specific words in a MsExcel spreadsheet and format
them (using either a macro or formula) with multiple font colors

(e.g. search for "MY NAME IS TIM", and format it so the word "NAME" would be
BOLD RED, and all the other text would be black.

I'm basically trying to highlight individual words only, but not the entire
text string or the entire cell.

Is there a way to do this with either a formula or macro?




  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Multiple Formats per Cell

Thanks.

Curious though. How does Excel and the macro know which word(s) to look for
if you removed the inputbox?


Gord Dibben MS Excel MVP

On Fri, 5 Dec 2008 17:50:10 -0800, Timo
wrote:

Close enough. I was able to modify your suggested macro to fit my needs. I
actually took out the InputBox so the macro would automatically check for the
words, and had to eliminate the code resetting the font color to 0, so I use
it to search for and modify several different words.

Thank you!!!!

"Gord Dibben" wrote:

So the text string doesn't matter?

Just the single word in any text string is what you're looking for?

Sub Highlight_Word()
Dim rng As Range
Dim ws As Worksheet
Dim Cell As Range
Dim myword As String
Dim start_str As Integer
Dim Mylen As Integer
Dim N As Single
myword = InputBox("Enter the word ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
For Each ws In ActiveWorkbook.Worksheets
ws.Select
With Selection
Set rng = Range(Range("A1"), Cells(Rows.Count, 1).End(xlUp))
For Each Cell In rng
Cell.Font.ColorIndex = 0
start_str = InStr(Cell.Value, myword)
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End With
Next ws
End Sub


Gord


On Tue, 2 Dec 2008 11:00:01 -0800, Timo
wrote:

This is a good start. Thanks! However, the only problem I have with this
sub is that it prompts me for the text string. I'm searching through several
hundred different text strings and trying to highlight specific words if they
appear in a specific column (within an entire workbook, not just one
worksheet).
Any further advice?


"Gord Dibben" wrote:

Timo

Sub color_words()
Dim Cell As Range, tempR As Range, mystring As String, _
myword As String, rng As Range
mystring = InputBox("Enter the search string")
If mystring = "" Then Exit Sub
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = UCase(mystring) Then
If tempR Is Nothing Then
Set tempR = Cell
Else
Set tempR = Union(tempR, Cell)
End If
End If
Next Cell
If tempR Is Nothing Then
End
End If
tempR.Select
myword = InputBox("Enter the word to format ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
Set rng = Selection
rng.Cells.Font.ColorIndex = 0
For Each Cell In rng
start_str = InStr(Cell.Value, UCase(myword))
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End Sub


Gord Dibben MS Excel MVP

On Wed, 26 Nov 2008 12:06:01 -0800, Timo
wrote:

I'm trying to search for specific words in a MsExcel spreadsheet and format
them (using either a macro or formula) with multiple font colors

(e.g. search for "MY NAME IS TIM", and format it so the word "NAME" would be
BOLD RED, and all the other text would be black.

I'm basically trying to highlight individual words only, but not the entire
text string or the entire cell.

Is there a way to do this with either a formula or macro?





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
Multiple formats in a single cell with multiple formulas Zakhary Excel Worksheet Functions 1 May 2nd 08 12:08 AM
Multiple formats in the same cell [email protected] Excel Worksheet Functions 2 January 16th 07 11:49 PM
Multiple formats within a cell gailann Excel Discussion (Misc queries) 5 June 7th 06 03:42 PM
Multiple formats for a single cell value. Carlos Excel Worksheet Functions 1 October 7th 05 12:44 AM
how do i use multiple conditional formats in one cell? tysonstone Excel Discussion (Misc queries) 1 January 21st 05 11:15 PM


All times are GMT +1. The time now is 08:16 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"