Microsoft Excel VBA sum function not working

时间:2016-10-19 13:35:38

标签: excel vba excel-vba

When i run the code i want the answer of the sum to be displayed in the cell (F 27).

But the sum function does not work nothing is printed into the cells when i run the code. I don't get any errors what so ever.

This is my code

Private Sub TextTotal1_Functions()

Dim SumTotal As Long

SumTotal = WorksheetFunction.Sum(Range("F9:F26"))

Range("F27") = SumTotal

Thanks for your help!

3 个答案:

答案 0 :(得分:1)

My guess is that you're not specifying the sheet correctly, try the below

Private Sub TextTotal1_Functions()

Dim SumTotal As Long

SumTotal = Application.WorksheetFunction.Sum(Sheets("MySheetNameHere").Range("F9:F26"))

Sheets("MySheetNameHere").Range("F27") = SumTotal

答案 1 :(得分:0)

我在VBA中使用WorksheetFunction时通常会做的是在即时窗口中写这样的内容:

?WorksheetFunction.Sum(selection)

并看看我是否从选择中得到了我期待的东西。

答案 2 :(得分:0)

可能计算设置为手动,因此将其设置回自动:

Application.calcualtion = xlCalculationAutomatic