Suganthan Srinivasan
Suganthan Srinivasan

Reputation: 31

How to make particular text in a cell Bold and Underlined

 strProject = Trim(ThisWorkbook.Sheets("Proposed").Cells(i, 2).Value)
       On Error Resume Next
       Set objWorkSheet = objWorkbook.Sheets("" & strProject & "")
       If Not objWorkSheet Is Nothing Then
            ThisWorkbook.Sheets("Proposed").Cells(i, 5).Value = Trim(objWorkSheet.Cells(12, 6).Value)
            ThisWorkbook.Sheets("Proposed").Cells(i, 6).Value = "Highlights for current week:" + Chr(10) + Trim(objWorkSheet.Cells(22, 2).Value) + Chr(10) + Chr(10) + "Action Plan for next Week:" + Chr(10) + Trim(objWorkSheet.Cells(27, 2).Value)

How do I make "Highlights for current week:" bold and underlined?

Upvotes: 2

Views: 5885

Answers (1)

David Rushton
David Rushton

Reputation: 5030

Yes you can. The bold and italic properties belong to the Font object, which can be accessed via a range object.

Example

ActiveCell.Font.Bold = True
ActiveCell.Font.Italic = True

This example updates the currently active cell.

Updated

If you only want to apply a style to part of a cell the syntax is a little different.

Partial Formatting Example

ActiveCell.Characters(Start:=1 Length:=10).Font.Bold = True

The start and length parameters control which characters are shown in bold.

Did you know Excel can write the VBA for you? Look for the macro recorder in the bottom left corner. When active Excel will translate your manual actions into VBA. This is a great way to discover the required code.

Upvotes: 5

Related Questions