Unable to format a cell containing maximum value

tina95

New Member
Joined
Apr 4, 2009
Messages
8
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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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:
Upvote 0
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.
 
Upvote 0
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>
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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