Find percentage of sums

A

Annette

Now that I have this code, there is one last step which I don't know how to
write. If I record, it will be based on specific cells, which I never know
where the end will be. WIth that said, I used the following code provided
earlier that works great, but I need to now take the result of these two
numbers to figure a percent. Specifically =sum(b?-c?)/c?


Dim LastRow As Long
LastRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row
Cells(LastRow + 1, 2).Formula = "=sum(b1:b" & LastRow & ")"

LastRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row
Cells(LastRow + 1, 3).Formula = "=sum(c1:c" & LastRow & ")"


How can I write take the last number in columnl b minus last row in column
c divided by last row in column c? The result will be listed in the last
row of column D.

Thanks much!
 
J

JLGWhiz

If you want the percentage of the difference between the sums to the sum of
C then:

x = Range("B" & LastRow).Value
y = Range("C" & LastRow).Value

Range("D" & LastRow) = (x-y)/y

If you want the percentage of the difference between the sums to the sum of
B then:

x = Range("B" & LastRow).Value
y = Range("C" & LastRow).Value

Range("D" & LastRow) = (x-y)/x
 
J

JLGWhiz

You probably will have to change all the "LastRow" references to "LastRow +
1" without the quote marks, of course.
 
A

Annette

This worked great ... thanks much
JLGWhiz said:
You probably will have to change all the "LastRow" references to "LastRow
+ 1" without the quote marks, of course.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top