Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

string formatting - Format a subset of text in Excel Cell Using Formula

I Have built a string using a formula in excel. as an example

Cell C3 contains text "Languages"
Cell C4 = "English, Spanish,German, French"
My Forumla = C3 & ":" & CHAR(10) & C4

The Desired text would be:

Languages:
English, Spanish, German, French

(where the bold text would actually be some color like red)

Is there a way to do this in Excel (change partial text formatting) .

I Have tried a formula... (Not working)

Function formatText(InText As Range)

'Set font color
  InText.Characters(1.5).Font.Color = Red
   'InText.Characters((InStr(1, ":", InText) + 1), (Len(InText) - InStr(1, ":", InText))).Font.ColorIndex = 3
End Function
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your posted function with work if and only if

  • It is called from a Sub (ie, as other have mentioned, not as a UDF)

And

  • the value(s) contained in range InText are string constants. (This is the main point of my answer)

It will not work for any cells in range InText containing a formula. AFAIK you cannot format part of a string returned by a formula.

BTW I would love to be proved wrong on this!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...