efan787
efan787

Reputation: 11

Microsoft Excel VBA sum function not working

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!

Upvotes: 1

Views: 2961

Answers (3)

Tauseef
Tauseef

Reputation: 1

Might be the Calculation is set to Manual, so set it back to Automatic:

Application.calcualtion = xlCalculationAutomatic

Upvotes: 0

Preston
Preston

Reputation: 8177

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

Upvotes: 1

Vityata
Vityata

Reputation: 43575

What I usually do when I use WorksheetFunction in VBA, is to write something like this in the immediate window:

?WorksheetFunction.Sum(selection)

and to see whether I am getting what I am expecting from the selection.

Upvotes: 0

Related Questions