Manolocs
Active Member
- Joined
- Mar 28, 2008
- Messages
- 340
Hello, I just got a VBA function from a very nice user of this forum Mr. Peter_SSs. This is my first time using VBA/Macros, so I need some help to figure out what I am doing wrong.
Any help is more than welcome.
The VBA code is the following:
- I have already the Developer TAB in excel 2013 PRO PLUS
- Macro security is Enable all Macros
- Thrust access to the VBA project object model is ticked
- New workbook > copy past some data needed to column A
- Developer TAB> VisualBasic> Select Sheet 1> Insert Module> Past the Macro
- First Dropdown list (General) Second SplitBold automatically
- Save As a Excel Macro Enabled Workb .xlsm
- Click on View Microsoft Excel (ALT+F11)
- Click on Macros>open a Window MacroName: without any saved Macro. Tried both items on the dropdown list (All Projects and Book1) no macro name is available.
- Tried to run the macro on the VB for Application windows but opens the same windows asking for the Macro name if I write SplitBold the create button is highlighted but comes a msg Name conflicts with existing module, project,or object library.
Any help is more than welcome.
The VBA code is the following:
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]