Different Styles within a single Cell

  • Thread starter Thread starter Jérémie Gent
  • Start date Start date
J

Jérémie Gent

Hi!

I would like a vb function to set a value into a cell, as well as different
styles within this cell.
For example, I would like to have in cells(1,1) the value "AB" where A would
be normal, and B would B bold (or another Font, another color, etc)
How do I do that from VB ?

Thanks!
 
Hi Jeremie,

for example:

With ActiveCell.Characters(Start:=2, Length:=1).Font
.FontStyle = "Bold"
End With

Maybe the most convenient way is to record a macro to see properies and
their values with different styles.

Regards,

Ivan
 
Sub gsnu()
Cells(1, 1) = "AB"
Cells(1, 1).Characters(Start:=1, Length:=1).Font.ColorIndex = 32
End Sub

will paint the first character blue. By specifying start and length each,
character can be assigned a different style
 
Thanks!

I noticed following behaviour though:
If I concatenate a string to the value of the cell, then the formatings of
the characters aren't kept.
For example, if I have AB with the B in blue like in your code Gary, then as
soon as I do something like
cells(1,1).value=cells(1,1).value & "C"
then the whole text ABC is in blue

Just as Information, doesn't bother me though.
I changed my procedure to generate first the whole text content of the cell,
then the formatting inside.
It works fine now.

Cheers
Jérémie
 

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