PDA

View Full Version : Change font for part of a cell



youngtrand
07-12-2012, 11:42 AM
Hey, i'm having trouble with this code, i'm sure it is just a simple fix

With Worksheets("Sheet1") _
.Range("B1") _
.Value = "New Title" _
.Characters(5, 5).Font.Bold = True
End With

Basically everything is fine, just I want to have this apply to cells that already have text in them, not have it put in the phrase "new title" and then bold the second word. Is this possible, example: In cell A2 I have the writing "excel is fun!" and i would like to be able to run the macro and have it change the "is fun" part bold. Ideally I would like to have this work for a range of cells as well, i.e. A1:B45.

jolivanes
07-12-2012, 12:59 PM
There might be people with ESP on this forum but it escapes me what the correlation is between The fifth ((5, 5) Character, bold the second word and bold the second and third word (is fun).

youngtrand
07-12-2012, 01:18 PM
I'm not sure if i understand your question, but the characters function in this just starts at the 5th character and then bolds the next 5 characters, does that help?

jolivanes
07-12-2012, 03:59 PM
If the (5, 5) does not change for any used cells in Range A1:B45 then it would be something like this.


Sub TryThis()
Dim c As Range
For Each c In Range("A1:B45")
If c.Value <> "" Then c.Characters(5, 5).Font.Bold = True
Next c
End Sub


If the last Row in Column A could be anywhere, you could try this.


Sub TryThisA()
Dim c As Range
Dim LR As Long
LR = Cells(Rows.Count, 1).End(xlUp).Row
For Each c In Range("A1:B" & LR)
If c.Value <> "" Then c.Characters(5, 5).Font.Bold = True
Next c
End Sub

youngtrand
07-13-2012, 11:35 AM
PERFECT!!! THANKS, YOU ARE AMAZING!!!

jolivanes
07-13-2012, 11:41 PM
This might be faster.

Sub TryThisA()
With ActiveSheet.UsedRange.SpecialCells(2)
.Characters(5, 5).Font.Bold = True
End With
End Sub