Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default identify a word in a string then change the format of that word

Using VBA
For each cell in a row, I want to identify a word in a string then
change the format of that word. For example,
For text in a cell " Id: 00098765 Description: For help with this
account number contact XYX Updates: This number is not useful."

I want the color of Id, Description, Updates changed to red and bold
and moved to a separate line in the same cell.
Id: 00098765
Description: For help with this account number contact XYX
Updates: This number is not useful."

Any help will be appreciated

Thank You

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default identify a word in a string then change the format of that word

One way:


Public Sub ColorWords()
Dim vWords As Variant
Dim rCell As Range
Dim i As Long
Dim nPos As Long

vWords = Array("Id", "Description", "Updates")
For Each rCell In Range("A1").Resize( _
1, Range("IV1").End(xlToLeft).Column)
With rCell
Application.EnableEvents = False
For i = LBound(vWords) To UBound(vWords)
nPos = InStr(1, .Text, vWords(i))
If nPos 1 Then _
.Value = Application.Substitute(.Text, _
vWords(i), vbLf & vWords(i))
Next i
Application.EnableEvents = True
For i = LBound(vWords) To UBound(vWords)
nPos = InStr(1, .Text, vWords(i))
If nPos 0 Then
With .Characters(nPos, Len(vWords(i))).Font
.Bold = True
.ColorIndex = 3
End With
End If
Next i
End With
Next rCell
End Sub


In article .com,
"EazyExcel" wrote:

Using VBA
For each cell in a row, I want to identify a word in a string then
change the format of that word. For example,
For text in a cell " Id: 00098765 Description: For help with this
account number contact XYX Updates: This number is not useful."

I want the color of Id, Description, Updates changed to red and bold
and moved to a separate line in the same cell.
Id: 00098765
Description: For help with this account number contact XYX
Updates: This number is not useful."

Any help will be appreciated

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default identify a word in a string then change the format of that word

JE McGimpsey,

Thnak you. This was vey helpful

Thanks once again

JE McGimpsey wrote:
One way:


Public Sub ColorWords()
Dim vWords As Variant
Dim rCell As Range
Dim i As Long
Dim nPos As Long

vWords = Array("Id", "Description", "Updates")
For Each rCell In Range("A1").Resize( _
1, Range("IV1").End(xlToLeft).Column)
With rCell
Application.EnableEvents = False
For i = LBound(vWords) To UBound(vWords)
nPos = InStr(1, .Text, vWords(i))
If nPos 1 Then _
.Value = Application.Substitute(.Text, _
vWords(i), vbLf & vWords(i))
Next i
Application.EnableEvents = True
For i = LBound(vWords) To UBound(vWords)
nPos = InStr(1, .Text, vWords(i))
If nPos 0 Then
With .Characters(nPos, Len(vWords(i))).Font
.Bold = True
.ColorIndex = 3
End With
End If
Next i
End With
Next rCell
End Sub


In article .com,
"EazyExcel" wrote:

Using VBA
For each cell in a row, I want to identify a word in a string then
change the format of that word. For example,
For text in a cell " Id: 00098765 Description: For help with this
account number contact XYX Updates: This number is not useful."

I want the color of Id, Description, Updates changed to red and

bold
and moved to a separate line in the same cell.
Id: 00098765
Description: For help with this account number contact XYX
Updates: This number is not useful."

Any help will be appreciated


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 to change format for an individual word in a cell jaysan3 Excel Discussion (Misc queries) 1 August 28th 09 11:03 AM
Add Word and change format Kelvin Excel Discussion (Misc queries) 2 November 24th 05 11:02 PM
Conditional format (word change) Onion Excel Worksheet Functions 2 February 8th 05 09:55 PM
Embedded word doc changed to image-need to change back to word. cflores Excel Discussion (Misc queries) 0 January 23rd 05 06:45 AM
Change format of single word in cell Zenon Excel Programming 1 June 22nd 04 04:02 PM


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