Change a given Function:

Manolocs

Active Member
Joined
Mar 28, 2008
Messages
340
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:

Code:
[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)
      [COLOR=darkblue]Else[/COLOR]
        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)
    [COLOR=darkblue]Else[/COLOR]
      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]
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
At a glance it seems like you could just change this line:
If r.Characters(pos, 1).Font.Bold

to

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.
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,680
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top