Using IF THEN based on font attribute

baseball

Board Regular
Joined
Apr 1, 2002
Messages
153
I have some data from the web that I want to turn into a database but a key part of the information I need is shown in that data by the bolding some of the names. I need to make an accompanying field (column) that says IF BOLD THEN 1 ELSE 0. Is there anyway of doing this other than VBA? I can use ASAP Utilities to select all the bolded names and then change their color, or something, if there is a way then to right the IF statement.
 
You can just add a custom function into your module:

Code:
Function isBold(target As Range) As Integer

    If target.Font.Bold = True Then isBold = 1 Else isBold = 0


End Function
 
Upvote 0
You can just add a custom function into your module:

Code:
Function isBold(target As Range) As Integer

    If target.Font.Bold = True Then isBold = 1 Else isBold = 0
 
End Function
Your function can be shortened to this (make sure to note the minus sign)...

Code:
Function isBold(Target As Range) As Long
  isBold = -Target.Font.Bold
End Function
 
Upvote 0
Thank you, I can't say that I understand why that one works but as long as it gets the job done as I have 50K, or so, records to deal with.
 
Upvote 0
Your function can be shortened to this (make sure to note the minus sign)...

Code:
Function isBold(Target As Range) As Long
   isBold = -Target.Font.Bold
 End Function
Thank you, I can't say that I understand why that one works...
Target.Font.Bold will return either True or False, which are Boolean value. Boolean values have numerical equivalents... in VB False has a numerical equivalent of 0 (zero) and True has a numerical equivalent of -1 (minus one). Note this is different than the Worksheet's TRUE value which has a numerical equivalent of 1 (plus one). Booleans are automatically converted to their numerical equivalents when you involve them in a mathematical operation. Putting the minus sign in front of Target.Font.Bold is the equivalent of multiplying by -1 (minus 1), so when Target.Font.Bold returns True, the minus one the minus sign is equivalent to is multiplied by the -1 that Target.Font.Bold returns to produce a value of 1 (minus one time minus one equals plus one) which is what you wanted returned when the font is bold. The minus one, which the minus sign in front front of Target.Font.Bold is equivalent to, when multiplied by the 0 (zero) that False is numerically equivalent to equates to 0 which is what you wanted returned when the font is not bold.
 
Upvote 0
Ah. I don't know VB, so obviously I was unaware that True had a numerical value of -1. Makes sense now.
 
Upvote 0

Forum statistics

Threads
1,226,795
Messages
6,193,046
Members
453,772
Latest member
aastupin

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