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
    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
    Cells(emptyRow, 5).Value = "RISK:" & Chr(10) & Identification.Value & " " & Chr(10) & "IMPACT:" & Chr(10) & Impact.Value 
        BoldWord Cells(emptyRow, 5), "RISK"
        BoldWord Cells(emptyRow, 5), "IMPACT"


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

    Code
    Option Compare Text

    in the General Declarations section then make sure case matches.

  • Re: Userform Text Transfer in Bold and Underlined


    Now I understand why I could get it to work.


    Brilliant thank you works as I need it to.


    Much appreciated!!!

  • 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]

  • Re: Userform Text Transfer in Bold and Underlined


    So when completing the sub, do you have to activate all 3 (bold,underlined,italic) or can you just use the a mixture of the ones you want?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!