Office & Productivity Software forum

General discussion

I need a excel macro code to carry out a formula.

by CNN80 / May 3, 2010 5:24 AM PDT

The formula is
D = [ sum from 1 to Nt( {(X - Xave)}^2 / Nt) ]^ 0.5

I need the answer to be in cell F2 and I'm trying to avoid having a new column containing the data
{(X - Xave)}^2 / Nt).

Xs are in Column A

Nt is unknown and this code will be used for different workbooks, same sheet (1) but different values of Nt.


Post a reply
Discussion is locked
You are posting a reply to: I need a excel macro code to carry out a formula.
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: I need a excel macro code to carry out a formula.
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
I can see an immediate problem
by MarkFlax Forum moderator / May 3, 2010 6:49 AM PDT

If Nt is unknown, then 1 to Nt is meaningless, and division by Nt is also meaningless.

I suspect you mean that Nt is defined elsewhere, perhaps in each workbook, but could be different for different workbooks.

What is Xave ? I haven't seen that mathematical expression before. Or do you mean an average of all the entries in col A?

Why do you need a macro for this? If there are explanations for the Nt and Xave above, then I'm sure the formula you have given can be worked into any cell, eg F2, even if it has to be worked on a bit.

Any new columns can be hidden of course.

But then your expression starts with D = .... What is D?


Collapse -
by CNN80 / May 3, 2010 5:22 PM PDT

Sorry, let me clear up some things.

Nt is the number of Xs i.e the number of rows in column A with data. It is unknown but I know there is a code for finding the last occupied cell in a column so it can be found.

Xave is the average of the data.

D is the value I'm trying to calculate.

E.g Z = x + y where x and y are data in colunms A and B respectively. Z would now be a new colunm populated with x + y.

I need a macro beacause I have more than 2 GB woth of data to work with. I've already done this without a macro for about 20 files and trust me, it's tirirng. I can't copy and paste the formula because the number of cells are different for each case.

Collapse -
Ahh got it,
by MarkFlax Forum moderator / May 3, 2010 9:13 PM PDT
In reply to: Clarification

and thanks for that CNN80.

I can also see now why you need that macro.

Hopefully others here will be able to help with that, but what about working with this in the meantime...?

You may want to work on a couple of dummy, (copied), sheets, saved in a completely different location, in case you make an error and lose anything. In fact, I would copy all of the original workbooks and place them off the hard disk somewhere, a backup.

Do this manually once more. But before doing it, "Record a macro", by going to Macros > Record a macro. Fill in the blanks, Macro name, Shortcut key if you want it, or create an object button, and make it available for any worksheet.

Then carry out the steps you would do manually to make this formula work. When you're done, Stop the recording.

Since all of your data is presented in the same form and same cell locations in each sheet, that same macro should work for each.

Would that work?

Good luck.


Collapse -
by CNN80 / May 3, 2010 9:22 PM PDT
In reply to: Ahh got it,

I've tried that. First of all, the number of the rows are different and the macro record me adding and finding the mean of a certain number of rows. Second, for me to do it manually, I had to create a second column with the values of

((X - Xave)^2)/Nt

then add them, put the value in another cell, then find the square root of that cell.

I couldn't figure out a way to modify the code for any number of cells.

Popular Forums
Computer Help 51,224 discussions
Computer Newbies 10,453 discussions
Laptops 20,090 discussions
Security 30,722 discussions
TVs & Home Theaters 20,937 discussions
Windows 10 1,295 discussions
Phones 16,252 discussions
Windows 7 7,684 discussions
Networking & Wireless 15,215 discussions


What do the color stripes mean on your tires?

Brian Cooley tells you why you might see various color lines on the wheels of your automobile.