Set Range only where cells have bold font

Eserino

New Member
Joined
Nov 3, 2016
Messages
5
Hello, can anyone help me (if its even possible) to set range for other excel integrated functions, like MAX, LARGE,... in one row, but only where the values are bold? Is it even possible?

I have a table where are 20+ columns and some of the values in a single row are bold. (the count of bold values/cells changes every day)
I need to apply i.e. function MAX on each row, but only for bolded values.
It would be helpfull, if I could get the cells with bold value as range reference.

Example: =MAX(onlyBoldCells)

Thanks anyone who can help me.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I think you'll need to use some VBA

Code:
Public Function BMAX(rng As Range)
Dim mRng As Range
Dim c As Range
For Each c In rng
    If c.Font.Bold Then
        If mRng Is Nothing Then
            Set mRng = c
        Else
            Set mRng = Union(mRng, c)
        End If
    End If
Next c


If mRng Is Nothing Then
    BMAX = 0
Else
    BMAX = Application.WorksheetFunction.Max(mRng)
End If


End Function

WARNING!!
The formulas will not update if the cell formatting is changed. You will need to recalculate.


Excel 2010
ABCDEFG
11234551
21234554
31234552
41234555
Sheet2
Cell Formulas
RangeFormula
F1=MAX(A1:E1)
G1=BMAX(A1:E1)
 
Last edited:
Upvote 0
You can do this on the sheet using a helper column and the GET.CELL function but it doesn't update if you change the bold settings of the cells, you need to recalculate. So rather than go through the fine details of how to do this can I ask a question first? You must have some logic to decide which cells are bold so can you not use this to decide which cells to include in the range?
 
Upvote 0
I think you'll need to use some VBA

Code:
Public Function BMAX(rng As Range)
Dim mRng As Range
Dim c As Range
For Each c In rng
    If c.Font.Bold Then
        If mRng Is Nothing Then
            Set mRng = c
        Else
            Set mRng = Union(mRng, c)
        End If
    End If
Next c


If mRng Is Nothing Then
    BMAX = 0
Else
    BMAX = Application.WorksheetFunction.Max(mRng)
End If


End Function

WARNING!!
The formulas will not update if the cell formatting is changed. You will need to recalculate.

Excel 2010
ABCDEFG

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]4[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]2[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]5[/TD]

</tbody>
Sheet2

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]F1[/TH]
[TD="align: left"]=MAX(A1:E1)[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]G1[/TH]
[TD="align: left"]=BMAX(A1:E1)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]


Thanks Comfy,

I am glad, I had the same approach, I got the same code (I modified some code I googled) except aplying
"BMAX = Application.WorksheetFunction.Max(mRng)"

This will work, but is it possible to get the value of the variable "mRng" to be used as range for other formulas?
I.E. =LARGE(mRng.value;2)/MAX(mRng.value) without to modify VB code for every change/excelFunction?

Or with other words, how can be the function BMAX modified, so that the output will every time be a range?

Usage like this:

=LARGE(BMAX(A1:E1),2)/MAX(BMAX(A1:E1))

Is it possible to get the result of BMAX like $B$2,$B$3,$B$4 or $B$2:$B$4 (coresponding to your image/table)
Or I.E. $R$1:$R$5,$R$7,$R$11

Does it have to be an array or what?
Thanks for help.
 
Upvote 0
Hi,
really it deosn't have any logic. I get every day some tables where other people "bold" some values (each time different)
I already read the topic of ussage of GET.CELL, but it is, as you mentioned, some conditional logic behind.
 
Upvote 0
Something like this:


Excel 2010
EFGHIJK
121234564
131234594
1412345#VALUE!#VALUE!
151234563
1612345145
Sheet2
Cell Formulas
RangeFormula
J12=SUM(BRNG(E12:I12))
K12=MAX(BRNG(E12:I12))


Code:
Public Function BRNG(rng As Range) As Range
Dim mRng As Range
Dim c As Range
For Each c In rng
    If c.Font.Bold Then
        If mRng Is Nothing Then
            Set mRng = c
        Else
            Set mRng = Union(mRng, c)
        End If
    End If
Next c


    Set BRNG = mRng
End Function
 
Last edited:
Upvote 0
#VALUE will be returned because mRng Is Nothing.

How do you want to handle ranges where non of the cells are Bold?

I'm not sure is returning zero is the answer, so left it as an error for now.
 
Upvote 0
Thank you very much.
Now I am ashamed :biggrin:
Grrrr, got this 2 hours ago, but I forgot to change the variable to range.
Sorry guys for consuming your time. Not that I am writing VB code every day.
 
Upvote 0
#VALUE will be returned because mRng Is Nothing.

How do you want to handle ranges where non of the cells are Bold?

I'm not sure is returning zero is the answer, so left it as an error for now.

Thats the smallest problem.
There must be at least one value bold. I know it is not comfort from excel point of view, but for now it is OK.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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