Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba calculations

ResolvedVersion 2003

James has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
Excel VBA Advanced course

VBA Calculations

I have a row of numbers and I want to calculate the average and standard deviation of these numbers using the excel functions within a macro. I don't want to output the results, I need it for a loop within the macro.

What is the code for this type of operation?

Thanks,

James

0788 1546 946

RE: VBA Calculations

Hello James

Thank you for your post.

We do not have any VBA trainers available currently to assist with your request as they are all training today.

I can refer your question to a VBA trainer for review, however you may not receive a response until sometime next week.

Amanda

RE: VBA Calculations

Hi James

Thank you for your question

The following code will solve your problem for you

Sub ElemStats()

Dim dblMean As Double
Dim dblStDEv As Double


dblMean = Application.WorksheetFunction.Average(Range("b2:e2"))

MsgBox dblMean

dblStDEv = Application.WorksheetFunction.StDev(Range("b2:e2"))

MsgBox dblStDEv

End Sub


The critical lines of code use the worksheet function method of the application object to calculate the arithmentic mean and the standard deviation of a row of numbers in the range "b2:e2".

I have used msgboxes to output the results, but this is obviously not essential and you can just manipulate the variables as you wish

Regards

Stephen

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Highlighting a data range

Attempting to use a mouse to highlight a large range of cells with data in Excel can make the mouse to have a life of it's own!

Use keyboard strokes instead.

Step 1. Place the cusor in the cell where the highlighting should begin.

Step 2. Select keystroke, CTRL+SHIFT+END

This will take the cursor to the furthermost bottom corner of the data range found in that worksheet. And highlight that range of cells at the same time




View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.