ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Different Styles within a single Cell (https://www.excelbanter.com/excel-programming/359226-different-styles-within-single-cell.html)

Jérémie Gent

Different Styles within a single Cell
 
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!



Ivan Raiminius

Different Styles within a single Cell
 
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


Jérémie Gent

Different Styles within a single Cell
 
Thanks Ivan, that's just great!
And quick!

Best
Jérémie

"Ivan Raiminius" schrieb im Newsbeitrag
ups.com...
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




Gary''s Student

Different Styles within a single Cell
 
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
--
Gary's Student


"Jérémie Gent" wrote:

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!




Jérémie Gent

Different Styles within a single Cell
 
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


"Gary''s Student" schrieb im
Newsbeitrag ...
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
--
Gary's Student


"Jérémie Gent" wrote:

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!







All times are GMT +1. The time now is 01:29 PM.

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