我知道有可能将文本复制到新单元格并对其应用格式。 但理想的结果是将格式化文本放在同一个单元格中。
我有一个VBA函数,它可以替换一些文本:
它在excel单元格中的样子:=formStepDescription([@[Step Template]];[@[ST Parameters]];parameters;$A$1)
但它的输出是纯文本,我需要突出我的替换。
关键是参数可能会发生变化,公式应该动态重新计算。
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