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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,516
Messages
6,125,285
Members
449,218
Latest member
Excel Master

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