Changing font within cell using VBA

  • Thread starter Thread starter stainless
  • Start date Start date
S

stainless

I have a VBA macro in Excel 2003 that puts a word within text already
in a cell. I want this word to appear as normal font when the rest of
the text in the cell is in bold.

How can I define the font of a substring of a cell?

Cheers

Mark
 
Hi Mark,

Have you tried the macro recorder? This should give you the basis of code
you need. Here is an example of recorded macro code...


ActiveCell.FormulaR1C1 = "Hello world"
With ActiveCell.Characters(Start:=1, Length:=5).Font
.Name = "Arial Black"
.FontStyle = "Bold"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With
With ActiveCell.Characters(Start:=6, Length:=6).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With


You can do some things to individual characters within a cell, but not too
much. Hopefully this will get you started though. Don't forget about the
macro recorder!
 
Mark,

You can use the macrorecorder to see what the VBA-code will become if you
change a cell in the way you wish.

Jan
 
and you could refine it to

with ActiveCell 'untested
.font.fontstyle="Bold"
.Characters(Start:=1, Length:=5).Font.FontStyle = "Regular"
end with
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top