-
Change font for part of a cell
Hey, i'm having trouble with this code, i'm sure it is just a simple fix
[VBA]With Worksheets("Sheet1") _
.Range("B1") _
.Value = "New Title" _
.Characters(5, 5).Font.Bold = True
End With [/VBA]
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.
Last edited by Aussiebear; 07-12-2012 at 04:28 PM.
Reason: Added the correct tags to the supplied code
-
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).
-
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?
-
If the (5, 5) does not change for any used cells in Range A1:B45 then it would be something like this.
[vba]
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
[/vba]
If the last Row in Column A could be anywhere, you could try this.
[vba]
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
[/vba]
Last edited by Aussiebear; 07-12-2012 at 04:30 PM.
Reason: Added the correct tags to the supplied code
-
PERFECT!!! THANKS, YOU ARE AMAZING!!!
-
This might be faster.
[VBA]Sub TryThisA()
With ActiveSheet.UsedRange.SpecialCells(2)
.Characters(5, 5).Font.Bold = True
End With
End Sub[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules