Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Changing font of part of text in a cell

Hello,
Using VBA, I am trying to use Instr and Range(x).characters to change part
of a cell's text in Excel 97.
I do a loop to find a cell with the same text as a control cell, but as the
text may be at different points in a cell, (e.g. one might say "Try this"
and the other might say "try again". How can I get Excel to find the "try"
in cell A2 and embolden the "try" but not the rest if it matches the "try"
in another cell (found in a loop)? It's got me beat!
Thanks if you can help!
Ross


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Changing font of part of text in a cell

Sub test()
SetBoldON Range("E7"), 4, 3
End Sub

Sub SetBoldON(ByRef Target As Range, lStart As Long, lLength As Long)
With Target.Cells.Characters(start:=lStart, length:=lLength).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

End Sub


Patrick Molloy
Microsoft Excel MVP
----------------------------------
"Ross Withey" wrote in message
...
Hello,
Using VBA, I am trying to use Instr and Range(x).characters to change part
of a cell's text in Excel 97.
I do a loop to find a cell with the same text as a control cell, but as

the
text may be at different points in a cell, (e.g. one might say "Try this"
and the other might say "try again". How can I get Excel to find the "try"
in cell A2 and embolden the "try" but not the rest if it matches the "try"
in another cell (found in a loop)? It's got me beat!
Thanks if you can help!
Ross




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Changing font of part of text in a cell

Sub AAAA()
For i = 1 To 100
Set rng = Cells(i, "A")
If InStr(1,rng, Range("B9"),vbTextCompare) 0 Then
iloc = InStr(1,rng, Range("B9"),vbTextCompare)
rng.Characters(iloc, Len(Range("B9"))).Font.Bold = True
End If
Next

End Sub

Tested in xl97, SR2

--
Regards,
Tom Ogilvy

Ross Withey wrote in message
...
Hello,
Using VBA, I am trying to use Instr and Range(x).characters to change part
of a cell's text in Excel 97.
I do a loop to find a cell with the same text as a control cell, but as

the
text may be at different points in a cell, (e.g. one might say "Try this"
and the other might say "try again". How can I get Excel to find the "try"
in cell A2 and embolden the "try" but not the rest if it matches the "try"
in another cell (found in a loop)? It's got me beat!
Thanks if you can help!
Ross




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Changing font of part of text in a cell

Thanks for your help, Tom and Patrick. One more thing..!
Having changed part of the cell text, is it possible to copy it elsewhere?
Range("A1").characters only seems to support the .font property and does not
allow copying. Do you know of a workaround?
Thanks!

"Ross Withey" wrote in message
...
Hello,
Using VBA, I am trying to use Instr and Range(x).characters to change part
of a cell's text in Excel 97.
I do a loop to find a cell with the same text as a control cell, but as

the
text may be at different points in a cell, (e.g. one might say "Try this"
and the other might say "try again". How can I get Excel to find the "try"
in cell A2 and embolden the "try" but not the rest if it matches the "try"
in another cell (found in a loop)? It's got me beat!
Thanks if you can help!
Ross




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Changing font of part of text in a cell

You can copy the cell - copying anything else will lose the rich text
formatting (although you could reapply it.)

--
regards,
Tom Ogilvy

Ross Withey wrote in message
...
Thanks for your help, Tom and Patrick. One more thing..!
Having changed part of the cell text, is it possible to copy it elsewhere?
Range("A1").characters only seems to support the .font property and does

not
allow copying. Do you know of a workaround?
Thanks!

"Ross Withey" wrote in message
...
Hello,
Using VBA, I am trying to use Instr and Range(x).characters to change

part
of a cell's text in Excel 97.
I do a loop to find a cell with the same text as a control cell, but as

the
text may be at different points in a cell, (e.g. one might say "Try

this"
and the other might say "try again". How can I get Excel to find the

"try"
in cell A2 and embolden the "try" but not the rest if it matches the

"try"
in another cell (found in a loop)? It's got me beat!
Thanks if you can help!
Ross






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
Changing the font for part of an axis label, not the whole label. amy45 Charts and Charting in Excel 2 April 5th 23 01:11 PM
Changing the font of text in a check box Iriemon Excel Worksheet Functions 3 December 2nd 09 09:16 PM
Using a changing cell reference as part of a workbook name 2 link Jason Excel Discussion (Misc queries) 2 June 12th 09 04:24 PM
Changing Font Size Doesn't Allow More Text to Fit in Cell NicoleS Excel Discussion (Misc queries) 4 December 4th 08 08:57 PM
changing font color for new text DanDavis Excel Discussion (Misc queries) 2 July 24th 05 04:17 PM


All times are GMT +1. The time now is 11:49 AM.

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"