Auto Size Font, VBA?

BWMagee

Board Regular
Joined
Feb 18, 2014
Messages
112
Hi, I have a spreadsheet with multiple formulas that return #DIV/0!

For the working of my spreadsheet this is fine, as data might be input later that will then yield a value. However they distract from the appearance of the spreadsheet, so I'm wondering if there is VBA code that can say something like:

For Spreadsheet Named "Sheet1"
Font Size of "#DIV/0!" to 6pt.

Many thanks!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Rather than VBA how about conditional format?
Whilst you cant change the font size, you could make the font white (It "disappears"), or maybe a light grey
 
Upvote 0
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Not sure if this may slow down your sheet performance.
Font size changes from 12 to 6 depending on result.

Code:
Private Sub Worksheet_Calculate()
Dim c As Range
    For Each c In ActiveSheet.UsedRange
        If c.Text = "#DIV/0!" Then
            c.Font.Size = 6
        Else
            c.Font.Size = 12
    End If
    Next
End Sub
 
Upvote 0
Rather than VBA how about conditional format?
Whilst you cant change the font size, you could make the font white (It "disappears"), or maybe a light grey

Good idea. Conditional format won't let me select #DIV/0! only (has to apply to all Errors), but will make the text light grey so I can still see the other errors when they display. Thanks!

Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Not sure if this may slow down your sheet performance.

Unfortunately it slowed down my sheet performance to the point it wouldn't respond (it's a large sheet). Nonetheless, thanks for the response!
 
Upvote 0
Good idea. Conditional format won't let me select #DIV/0! only (has to apply to all Errors), but will make the text light grey so I can still see the other errors when they display. Thanks!
Yes it will, use a formula to determine which cells & then use this
=ERROR.TYPE(A1)=2
 
Last edited:
Upvote 0
Since you did not say what range to look in my script looked in the entire sheet.
We maybe could use cell change but would need to know the range and what causes the cell change.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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