Find percentage of sums

  • Thread starter Thread starter Annette
  • Start date Start date
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!
 
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
 
You probably will have to change all the "LastRow" references to "LastRow +
1" without the quote marks, of course.
 
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.
 
Back
Top