# Unable to format a cell containing maximum value

#### tina95

##### New Member
I have just started learning VBA. I want to find the maximum value from absolute values of cells and then format that cell by bolding it. I am able to find the max value of the absolute values of cells in the row by the code:

Maxx1= Application.WorksheetFunction.Max((Abs(Range("B11"))), (Abs(Range("C11"))), (Abs(Range("D11"))))...
However, if I do maxx1.select
or
maxx1.font.fontstyle = "Bold",
it gives an error "Object required".

Thus I am not able to format it.

Any inputs on this would be greatly appreciated.

### Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

#### Peter_SSs

##### MrExcel MVP, Moderator
I have just started learning VBA. I want to find the maximum value from absolute values of cells and then format that cell by bolding it. I am able to find the max value of the absolute values of cells in the row by the code:

Maxx1= Application.WorksheetFunction.Max((Abs(Range("B11"))), (Abs(Range("C11"))), (Abs(Range("D11"))))...
However, if I do maxx1.select
or
maxx1.font.fontstyle = "Bold",
it gives an error "Object required".

Thus I am not able to format it.

Any inputs on this would be greatly appreciated.
Tina

Welcome to the MrExcel board!

Do you need to use vba for this? Would this standard Conditional Formatting do? In my example, I selected B11:G11 and then applied the Conditional Formatting shown.

Excel Workbook
BCDEFG
1125-12-328314
CF MAX
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B111. / Formula is =ABS(B11)=MAX(ABS(\$B\$11:\$G\$11))Abc

Last edited:

#### tina95

##### New Member
Hi Peter,
Thank you very much for your reply. However, this is just part of a big project I am working on so VBA would be required for this.
Any inputs on this would be really appreciated.

#### Peter_SSs

##### MrExcel MVP, Moderator
Try this

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Max_Abs()<br>    <SPAN style="color:#00007F">Dim</SPAN> myRange <SPAN style="color:#00007F">As</SPAN> Range, c <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> myMax <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, myMin <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, Maxx1 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br>    <br>    <SPAN style="color:#00007F">Set</SPAN> myRange = Range("B11", Cells(11, Columns.Count).End(xlToLeft))<br>    myMax = Abs(WorksheetFunction.Max(myRange))<br>    myMin = Abs(WorksheetFunction.Min(myRange))<br>    Maxx1 = IIf(myMax > myMin, myMax, myMin)<br>    myRange.Font.Bold = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> myRange<br>        <SPAN style="color:#00007F">If</SPAN> Abs(c.Value) = Maxx1 <SPAN style="color:#00007F">Then</SPAN><br>            c.Font.Bold = <SPAN style="color:#00007F">True</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> c<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

#### tina95

##### New Member
Hello Peter,

This works. I thank you so much for your help.

Regards,
Natalie

Replies
5
Views
140
Replies
4
Views
168
Replies
11
Views
242
Replies
15
Views
814
Replies
0
Views
97

1,127,383
Messages
5,624,375
Members
416,025
Latest member
VN5968

### 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.

### Which adblocker are you using?

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

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