+ Reply to Thread
Results 1 to 2 of 2

Bolding a text string variable within a string with variable text strings prior

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    594

    Bolding a text string variable within a string with variable text strings prior

    String variables:
    strAnimal
    strThing
    strNature
    strExclamation

            .Range("B9") = "The little " & strAnimal & " jumped over the " & strThing & " in the " & strNature & ", and said " & strExclamation
    OK, in the above, my contemplated solution to make strNature show up in bold font is to get the length of each of the preceding variables (strAnimal & strThing), add that to the stipulated text prior to strNature (36), add the two together (let's call that lResult, a long variable, so if strAnimal is 12 and strThing is 10 we would have 36 + 12 + 10 = 58, lResult = 58) and then write:

        wsStory.Range("B9").Characters(Start:=58, Length:=Len(strNature)).Font.FontStyle = "Bold"
    Is there an easier way to accomplish this? This isn't the only time i need to bold something within a text string, so if there is a shortcut, i want to know!

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,661

    Re: Bolding a text string variable within a string with variable text strings prior

    TempStr = "The little " & strAnimal & " jumped over the " & strThing & " in the " & strNature & ", and said " & strExclamation
    BoldStart = InStr(TempStr, strNature)
    ChrCount = Len(strNature)
    With .Range("B9")
        .Value = TempStr
        .Characters(Start:=BoldStart, Length:=ChrCount).Font.FontStyle = "Bold"
    End With
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Storing complex text string into variable. Text string contains html or xml code.
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-20-2015, 04:54 AM
  2. Replies: 3
    Last Post: 02-17-2015, 11:53 PM
  3. Add text to a string variable.
    By Marvin85 in forum Excel General
    Replies: 1
    Last Post: 01-28-2015, 05:56 PM
  4. [SOLVED] Find Text String via variable
    By petreli in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2013, 12:57 PM
  5. [SOLVED] Extracting Text from a string of Text & Digits of variable length
    By hastex in forum Excel General
    Replies: 6
    Last Post: 06-06-2012, 09:11 AM
  6. Replies: 6
    Last Post: 03-08-2012, 10:35 AM
  7. [SOLVED] EXTRACT TEXT FROM TEXT STRING:The names are of variable length
    By carricka in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-08-2005, 06:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1