可以通過編寫 VBA 宏來實現統計數字在表格中出現次數的功能。具體而言,可以將以下代碼插入到 VBA 編輯器中:
Sub CountNumber()
Dim Rng As Range
Dim Number As Double
Dim Count As Integer
Set Rng = Application.InputBox("Select a range:", "Count Number", Type:=8)
Number = Application.InputBox("Type in a number:", "Count Number", Type:=1)
For Each Cell In Rng
If Cell.Value = Number Then
Count = Count + 1
End If
Next
MsgBox "Number " & Number & " appears " & Count & " times."
End Sub
這段代碼包括一個名為 CountNumber 的子過程,該過程中使用 InputBox 函數獲取用戶輸入的區域和數字,并使用 For 循環遍歷該區域并統計數字出現次數。最后,使用 MsgBox 函數顯示數字出現次數的結果。