Formatting Parts of a Sentence
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Formatting Parts of a Sentence

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    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 ]

  2. #2
    MrExcel MVP Jay Petrulis's Avatar
    Join Date
    Mar 2002
    Location
    Chicago, IL USA
    Posts
    2,040
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Thanks Jay!
    I appreciate very much!

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com