Formatting Parts of a Sentence

L

Legacy 98055

Guest
Hi

I know that you can, for instance, make part of a sentence bold while not affecting the original formatting of the rest in Excel.

My question for you is this:

I am entering a string into one cell via VBA.
Is there any way, using code, to format a selective part of any string.

Just in case I'm not clear, please see the example below:

MyString = "A walk in the park"

Would it be possible to send this string with 'park' having a larger font than the rest of the string?

If I cannot store this in a string, is there another way?

Thanks!
Tom
This message was edited by TsTom on 2002-03-23 08:14
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi Tom,

Changed the subject header, I see. I came back to the board and couldn't find the post at first.

The following routine searches the text and doubles the size of 'park' on the worksheet cell. The text is hardoced in the routine, but you can generalize this.

No error handling is included.

---begin VBA---
Sub Partial_Cell_Text()
Dim MyString As String, FindString As String
Dim MyPosition As Integer

MyString = "A walk in the park."
FindString = "park"

With Range("A1")
.Value = MyString
MyPosition = WorksheetFunction.Find(FindString, MyString, 1)
With .Characters(Start:=MyPosition, Length:=Len(FindString)).Font
.Size = .Size * 2
End With
End With

End Sub
---end VBA---

HTH,
Jay
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,541
Latest member
iparraguirre89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top