Userform Text Transfer in Bold and Underlined

  • Hi,


    Im working with a userform that transfers to a worksheet once complete.


    Two of the text boxes transfer into the same cell which works fine.


    But to better show the information is from two different sources I have added an extra word before each piece of information,

    Code
    1. Cells(emptyRow, 5).Value = "RISK:" & Chr(10) & Identification.Value & " " & Chr(10) & "IMPACT:" & Chr(10) & Impact.Value


    What im trying to do is make the "RISK:" and "IMPACT:" parts transfer in bold and underlined.


    Anyone able to show me how this is done as I cant seem to find a way to so.


    Many thanks

  • Re: Userform Text Transfer in Bold and Underlined


    You cannot change the attributes of part of the text in a textbox, it's all or nothing so setting the text bold will have to be done after the sheet is updated.


    Add to a standard code module



    Transfer the text as now then call the procedure. This can handle either single cells or a range of cells so how you do it is down to you.

    Code
    1. Cells(emptyRow, 5).Value = "RISK:" & Chr(10) & Identification.Value & " " & Chr(10) & "IMPACT:" & Chr(10) & Impact.Value
    2. BoldWord Cells(emptyRow, 5), "RISK"
    3. BoldWord Cells(emptyRow, 5), "IMPACT"


    Note that VBA is Case Sensitive by default, unless you are using

    Code
    1. Option Compare Text

    in the General Declarations section then make sure case matches.

  • Re: Userform Text Transfer in Bold and Underlined


    Glad it worked for you.


    Just as an example, I've modified it a little. The updated version will set the text attributes for Bold, UnderLined or Italicised, and can be used to add or remove those attributes



    You can combine the elements of the Enum (Bold, Italic & UnderScore). Sample calls:


    Underline & Bold the word 'Risk' ('True' is a default and can be omitted)[INDENT]FormatWord Cells(emptyRow, 5), "RISK", UnderLine + Bold, True [/INDENT]


    Turn off Italics, Bold & Underline for the word 'Risk'[INDENT]FormatWord Cells(emptyRow, 5), "RISK", Italic + UnderLine + Bold, False[/INDENT]