Running a macro to sum a range and having the average displayed in the next cell

memoorefield

New Member
Joined
Jun 17, 2015
Messages
14
I have a macro that sums column C with varying numbers of rows. It works great with no problems. I would like to also have the macro take that sum and divide it by the value in cell M and paste the new value in cell D. My current formula is below.

Const SourceRange = "C"
Dim NumRange As Range, formulaCell As Range
Dim SumAddr As String
Dim C As Long

For Each NumRange In Columns (SourceRange).SpecialCells(xlConstants, xlNumbers).Areas
SumAddr = NumRange.Address(False, False)
Set formulaCell = NumRange.Offset (NumRange.Count, 0).Resize(1, 1)
formulaCell.Formula = "SUM(" & SumAddr & ")"

c = NumRange.Count
Next NumRange
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I do not understand this"
Your quote:
"I would like to also have the macro take that sum and divide it by the value in cell M and paste the new value in cell D

Cell M Cell D ???

There is no Cell D Or Cell M
There is a cell M1 and a cell D1 or cell D2
But no cell M
 
Upvote 0
Sorry for the confusion... I meant the cell that is in column D and column M is in the same row of the Sum from the macro.
 
Upvote 0
memoorefield,

1. What version of Excel, and, Windows are you using?

2. Are you using a PC or a Mac?


I would like more information. Please see the Forum Use Guidelines in the following link:

http://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html


See reply #2 at the next link, if you want to show small screenshots.

http://www.mrexcel.com/forum/about-board/508133-attachments.html#post2507729


If you are not able to provide screenshots, then:

You can post your workbook/worksheets to the following free site (sensitive data changed), and provide us with a link to your workbook:

https://dropbox.com


3. And, can we see all of your macro code?

When posting VBA code, please use Code Tags - like this:

[code=rich]

Paste your code here.

[/code]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top