If I select a number of cells in Excel, I can see some functions on those in the Customized status bar. This information is my own selection out of the following:
I want to add to this list a function that calculates the ratio of non-blank cells. The function would be =COUNTA(range) / (COUNTA(range) + COUNTBLANK(range)), but how can I get that into the status bar? I don't have much experience in VBA, so some explanation would be welcome.
To customize the status bar, right-click on anywhere in the status bar and select the required option which we want to see in Status Bar. How to Customize Status Bar in Excel? By default, some of the options are already active in the excel status bar like Count, Sum, Average, etc.
You can apply custom functions in an Excel workbook in the same way as you use regular functions. For example, just write in a cell the formula below: UDF can be used in combination with regular functions. For example, add text to the calculated maximum value: You can find the number which is both maximum and is in the range from 10 to 50.
Cell Mode Option in Excel Status Bar. “Cell Mode” option is enabled by default in excel and can be seen at the extreme left side of the status bar. It has different modes listed below: Ready – It means the cell on which you have your cursor currently is ready to take user input from you.
Your custom functions appear in the User Defined category: An easier way to make your custom functions available at all times is to store them in a separate workbook and then save that workbook as an add-in. You can then make the add-in available whenever you run Excel.
Try something like this (Not the best way to do it though but solves your purpose)
Explanation: What this code does is checks if the user has selected a valid range (of minimum 2 cells) and then uses the Application.Evaluate
to calculate your formula and then display it in the status bar. Also note that I have not done any error handling. I am sure you will take care of it :)
Paste this in the relevant sheet code area.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If TypeName(Target) = "Range" Then
If Target.Cells.Count > 1 Then
Application.StatusBar = "My Function: " & _
Application.Evaluate( _
"=COUNTA(" & _
Target.Address & _
") / (COUNTA(" & _
Target.Address & _
") + COUNTBLANK(" & _
Target.Address & _
"))" _
)
End If
End If
End Sub
This is a very basic way of doing it. In case you want it applicable for all sheets then you will have to amend it accordingly.
Also the problem with this method is that it will suppress the application level messages in the status bar.
Screenshot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With