Change a given Function:


Active Member
Mar 28, 2008
Hello, I got this Function from Mr. Peter_SSs, it is working perfect, the function split Bold Words from not Bold.
My questions is, Can this function be changed to look for (italic and Capital letters font) instead of Bold? I don't need both together but would be good to have one function for each one.
Thanks in advance.:confused:

[COLOR=darkblue]Function[/COLOR] SplitBold(r [COLOR=darkblue]As[/COLOR] Range, [COLOR=darkblue]Optional[/COLOR] bBold [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Boolean[/COLOR] = [COLOR=darkblue]True[/COLOR]) [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
  [COLOR=darkblue]Dim[/COLOR] i [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], pos [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
  [COLOR=darkblue]Dim[/COLOR] Words [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
  [COLOR=darkblue]Dim[/COLOR] sBold [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], sUnbold [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
  [COLOR=darkblue]If[/COLOR] r.Cells.Count = 1 And Len(r.Cells(1).Value) [COLOR=darkblue]Then[/COLOR]
    Words = Split(r.Value)
    pos = 1
    [COLOR=darkblue]For[/COLOR] i = 0 [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](Words)
      [COLOR=darkblue]If[/COLOR] r.Characters(pos, 1).Font.Bold [COLOR=darkblue]Then[/COLOR]
        sBold = sBold & " " & Words(i)
        sUnbold = sUnbold & " " & Words(i)
      [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
      pos = pos + Len(Words(i)) + 1
    [COLOR=darkblue]Next[/COLOR] i
    [COLOR=darkblue]If[/COLOR] bBold [COLOR=darkblue]Then[/COLOR]
      SplitBold = Mid(sBold, 2)
      SplitBold = Mid(sUnbold, 2)
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
  [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
End [COLOR=darkblue]Function[/COLOR]

Scott Huish

MrExcel MVP
Mar 17, 2004
At a glance it seems like you could just change this line:
If r.Characters(pos, 1).Font.Bold


If r.Characters(pos, 1).Font.Italic

although you might also want to change all your variable names to have the word Italic instead of Bold for clarity.

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...