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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,539
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Apr 4, 2009
Messages
8
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
Joined
May 28, 2005
Messages
48,539
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Apr 4, 2009
Messages
8
Hello Peter,

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

Regards,
Natalie
 

Watch MrExcel Video

Forum statistics

Threads
1,129,876
Messages
5,638,788
Members
417,052
Latest member
Noobest

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
Top