6

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:

  • Average
  • Count
  • Numerical count
  • Minimum
  • Maximum
  • Sum

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.

4

1 に答える 1

7

このようなことを試してください(最善の方法ではありませんが、目的を解決します)

説明: このコードは、ユーザーが有効な範囲 (最小 2 セル) を選択したかどうかを確認し、 を使用しApplication.Evaluateて数式を計算し、ステータス バーに表示します。また、エラー処理を行っていないことにも注意してください。私はあなたがそれを大事にすることを確信しています:)

これを関連するシート コード領域に貼り付けます。

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

これは非常に基本的な方法です。すべてのシートに適用する場合は、それに応じて修正する必要があります。

また、この方法の問題は、ステータス バーにアプリケーション レベルのメッセージが表示されなくなることです。

スクリーンショット

ここに画像の説明を入力

于 2013-09-04T11:34:28.523 に答える