Understanding Cell Object

AEngineer

New Member
Joined
Nov 26, 2005
Messages
7
In "Excel VBA Power Programming 2016" Chapter 7 there is a function to determine where the format of a cell is Bold

Function ISBOLD(cell) As Boolean
' Returns TRUE if cell is bold
ISBOLD = cell.Range("A1").Font.Bold
End Function

It works when used in a spreadsheet and "cell" is an address such as "A2"
When I put it in sub I could not get it to work. If I changed "cell" to "range" then it worked fine.

My suspicion is that I'm not understanding what "cell" means. Is it an object like Range? If so, shouldn't cell.address do the same thing as ActiveCell.Range.Address?

I'd appreciate guidance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
In "Excel VBA Power Programming 2016" Chapter 7 there is a function to determine where the format of a cell is Bold

Function ISBOLD(cell) As Boolean
' Returns TRUE if cell is bold
ISBOLD = cell.Range("A1").Font.Bold
End Function

It works when used in a spreadsheet and "cell" is an address such as "A2"
When I put it in sub I could not get it to work. If I changed "cell" to "range" then it worked fine.

My suspicion is that I'm not understanding what "cell" means. Is it an object like Range? If so, shouldn't cell.address do the same thing as ActiveCell.Range.Address?

I'd appreciate guidance.



Going out on a limb here as this is my first reply to a query.

I think / hope that it might be that you need to define (Dim) Cell as a range and then Set the range to the cell you want to process.

but I could be wrong, so will be interested to read any follow ups.

Hj
 
Upvote 0
Hi,
When passing arguments like any other variable declaration in code, it is always good practice to declare their data type.

Cell I would have thought would be a Range Object & argument expressed as follows

Code:
Function ISBOLD(ByVal cell As Range) As Boolean
' Returns TRUE if cell is bold
ISBOLD = cell.Font.Bold
End Function


and as an example, call it like this

Code:
Sub abc()
 MsgBox ISBOLD(Cells(1, 1))
End Sub



Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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