Bolding specific words within a textbox

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,345
Office Version
  1. 365
Platform
  1. Windows
I have a textbox that will say various things depending upon how the macro is run. I am stuck on the "Else" part of my if/then statement where I want the outcome to read as follows:
Revenue:
(Increase)/Decrease

Expenses:
Increase/(Decrease)

Instead my macro is ouputing the following:

Revenue:

(Increase)/Decrease

Expenses:
Increase/(Decrease)


I can't figure out why the end of my text is getting bolded. Any thoughts?

Code:
<font face=Calibri>        <SPAN style="color:#007F00">'Update Increase/Decrease Textbox ("IncreaseDecreaseBox" is the name of the textbox)</SPAN><br>            ActiveSheet.Shapes("IncreaseDecreaseBox").OLEFormat.Object.Characters.Font.Bold = <SPAN style="color:#00007F">False</SPAN><br>            <br>            <SPAN style="color:#00007F">If</SPAN> SelectedStmt = "Assets" <SPAN style="color:#00007F">Then</SPAN><br>                ActiveSheet.Shapes("IncreaseDecreaseBox").TextFrame.Characters.Text = "Assets:" & vbNewLine & "Increase/(Decrease)"<br>                ActiveSheet.Shapes("IncreaseDecreaseBox").OLEFormat.Object.Characters(1, 7).Font.FontStyle = "Bold"<br>            <br>            <SPAN style="color:#00007F">ElseIf</SPAN> SelectedStmt = "Liabilities" <SPAN style="color:#00007F">Then</SPAN><br>                ActiveSheet.Shapes("IncreaseDecreaseBox").TextFrame.Characters.Text = "Liabilities:" & vbNewLine & "(Increase)/Decrease"<br>                ActiveSheet.Shapes("IncreaseDecreaseBox").OLEFormat.Object.Characters(1, 12).Font.FontStyle = "Bold"<br>            <SPAN style="color:#00007F">Else</SPAN><br>                ActiveSheet.Shapes("IncreaseDecreaseBox").TextFrame.Characters.Text = "Revenue:" & vbNewLine & "(Increase)/Decrease" & vbNewLine & vbNewLine & "Expenses:" & vbNewLine & "Increase/(Decrease)"<br>                ActiveSheet.Shapes("IncreaseDecreaseBox").OLEFormat.Object.Characters(1, 8).Font.FontStyle = "Bold"<br>                ActiveSheet.Shapes("IncreaseDecreaseBox").OLEFormat.Object.Characters(29, 38).Font.FontStyle = "Bold"<br>                <br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN></FONT>







 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I was able to figure out my problem with a little more research. I misunderstood how the Character object worked. I was assuming that the numbers inside the parenthesis were coordinates for a range of characters. Instead they are set up as follows: (start, length).....so I just had to change my last line to "Characters(29,11)" and I got the correct bolded area.
 
Upvote 0
Hi

I'm glad you figured it out.

Another option would be (just an example):

Code:
Sub Test()
Dim tBox As TextBox

Set tBox = ActiveSheet.TextBoxes("IncreaseDecreaseBox")

tBox.Font.Bold = False
tBox.Text = "Assets:" & vbNewLine & "Increase/(Decrease)"
tBox.Characters(1, 7).Font.Bold = True
End Sub
 
Upvote 0
Thanks PGC! I like that way better as it is much cleaner. I just posted another textbox question on a new thread if you wouldn't mind taking a look at it. I believe it should be another easy solution.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,678
Members
449,116
Latest member
HypnoFant

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