ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change Format of Only Some Text in Cell (https://www.excelbanter.com/excel-programming/391640-change-format-only-some-text-cell.html)

roadkill

Change Format of Only Some Text in Cell
 
The user interface for Excel allows you to select letters or words within a
string of text in a cell and change the format (bold, color, etc.) for just
the selected letters or words. I haven't been able to figure out how to do
this same selective formatting programmatically. Does VBA provide this
capability and, if so, how?

Thanks,
Will

John Huschka

Change Format of Only Some Text in Cell
 
Look for the "Characters" collection, which presents the text of a cell as a
collection of characters.
--
John Huschka


"roadkill" wrote:

The user interface for Excel allows you to select letters or words within a
string of text in a cell and change the format (bold, color, etc.) for just
the selected letters or words. I haven't been able to figure out how to do
this same selective formatting programmatically. Does VBA provide this
capability and, if so, how?

Thanks,
Will


Gary''s Student

Change Format of Only Some Text in Cell
 
from the recorder:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 6/19/2007
'

'
ActiveCell.FormulaR1C1 = "hello world"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With ActiveCell.Characters(Start:=2, Length:=3).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With ActiveCell.Characters(Start:=5, Length:=7).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("D9").Select
End Sub

--
Gary''s Student - gsnu200731


"roadkill" wrote:

The user interface for Excel allows you to select letters or words within a
string of text in a cell and change the format (bold, color, etc.) for just
the selected letters or words. I haven't been able to figure out how to do
this same selective formatting programmatically. Does VBA provide this
capability and, if so, how?

Thanks,
Will



All times are GMT +1. The time now is 08:53 AM.

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