Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

excel vba: make part of string bold

Tags:

excel

vba

I have excel cells which contain entries like this:

name/A/date
name/B/date
name/C/date

Cell content is displayed on multiple lines in the same cell. I would like to make only "name" bold for all entries. I recorded a macro and I think the solution must be something like this:

ActiveCell.FormulaR1C1 = "name/A/date" & Chr(10) & "name/B/date" & Chr(10) & "name/C/date"
With ActiveCell.Characters(Start:=25, Length:=4).Font
    .FontStyle = "Bold"
End With

What I don't know is how to get the start value and the length of each entry. Anyone got an idea?

like image 435
user366121 Avatar asked Apr 24 '12 09:04

user366121


People also ask

How do I bold only part of a cell in Excel?

In Excel, if you want to bold or underline specific words within a cell, you can just select the words you want and click Home-> Bold and Underline under Font tab. Then the specific words will be bold and underlined.

How do I bold a string in Excel VBA?

✎ To make a text or string bold, select that cell and set Font. Bold to True. ✎ To bold a specific range of cells, use the Range method.

How do I make cell contents bold in VBA?

Type the word you want to make bold into the "Find what:" field and the same into the "Replace with:" field, then when you are on the "Replace With:" box press CTRL B. You should see "Format: Font: Bold" appear beneath it. Click Replace All and you should see all the targeted words go bold.


1 Answers

Have it now:

lngPos = InStr(ActiveCell.Value, "/")
With ActiveCell.Characters(Start:=1, Length:=lngPos - 1).Font
    .FontStyle = "Bold"
End With
like image 159
user366121 Avatar answered Oct 04 '22 11:10

user366121