1

I know that there is a possibility to copy text to a new cell and apply formatting to it. But desirable result is to get formatted text in the same cell.

I have a VBA function, which makes some text replacements: How it looks like in excel cell: =formStepDescription([@[Step Template]];[@[ST Parameters]];parameters;$A$1) But it's output is plain text and I need to highlight my substitutions. The point is that parameters might change and formula should recalculate dynamically.

Function formStepDescription(stepDescriptionTemplate As Range, STParameters, tableWithValues As Range, mode)
    Dim stubsList() As String
    Dim parametersList() As String
    Dim valuesList() As String

    If STParameters = "" Then
        formStepDescription = stepDescriptionTemplate
    Else
        stubsList() = Filter(Split(stepDescriptionTemplate), "#param")
        parametersList() = Split(STParameters, Chr(10))
        valuesList = getValuesByIDs(parametersList, tableWithValues, mode)
        formStepDescription = stepDescription(stepDescriptionTemplate, valuesList, stubsList)
    End If
End Function
Private Function stepDescription(stepDescriptionTemplate, valuesList() As String, stubsList() As String)
    Dim stepDescriptionText As String

    stepDescriptionText = stepDescriptionTemplate

    For i = 0 To UBound(valuesList)
        stepDescriptionText = Replace(stepDescriptionText, stubsList(i), valuesList(i))
    Next

    stepDescription = stepDescriptionText
End Function
Community
  • 1
  • 1
Sunpark22
  • 11
  • 4
  • of course its possible using vba, but I assume you are not looking for that? – Steven Martin Dec 05 '15 at 11:30
  • @StevenMartin I am looking for any kind of solution, actually :) – Sunpark22 Dec 05 '15 at 11:36
  • 1
    Can you post a sample of what you want, you can always use conditional formatting with formulas to do things like bold and colours , if you need parts of a string formatted , then vba is needed – Steven Martin Dec 05 '15 at 11:37
  • @StevenMartin added some details in question. – Sunpark22 Dec 05 '15 at 11:48
  • Can you post the vba function, you will need to make the changes in the function using .font.color etc – Steven Martin Dec 05 '15 at 11:51
  • 1
    Possible duplicate of [Excel User Defined Function: change the cell's color](http://stackoverflow.com/questions/13705663/excel-user-defined-function-change-the-cells-color) – GSerg Dec 05 '15 at 12:23
  • @ScottCraner, He shows how to change other cells, but I need to apply rich text formatting for the cell with UDF – Sunpark22 Dec 05 '15 at 18:58

0 Answers0