tourless
Board Regular
- Joined
- Feb 8, 2007
- Messages
- 144
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I have invoice data separated with blank lines between invoice numbers and I'm currently using the following code which gives me the result of summing up the line items of a given invoice and it works fine. But what I would like to do is actually insert the sum formula for the rows that make up each invoice and insert that formula in the column to the right of the blank line which marks the end of a given invoice. The code I'm using should make it clearer...
The result is accurate as far as the math goes but my data range can have a value that extends to four decimal places which I have to truncate to two decimal places which can change the value of the sum and that new value is not reflected in my sum with the code I'm using because it only enters the value of the sum and not the formula for the sum. With that I'm not sure if it would be easier to round to the two decimal places before I run the code above or to try and make the change I'm looking for in the code.
I defer to you experts for advise.
Thanks.
I have invoice data separated with blank lines between invoice numbers and I'm currently using the following code which gives me the result of summing up the line items of a given invoice and it works fine. But what I would like to do is actually insert the sum formula for the rows that make up each invoice and insert that formula in the column to the right of the blank line which marks the end of a given invoice. The code I'm using should make it clearer...
VBA Code:
With ActiveSheet
lastRow = Cells(Rows.Count, "E").End(xlUp).Row
firstRow = 6
TempTotal = 0
For x = firstRow To lastRow + 1
If Cells(x, "E") <> "" Then
TempTotal = TempTotal + Cells(x, "E")
Else: Cells(x, "F") = TempTotal
Cells(x, "F").Interior.ColorIndex = 6
TempTotal = 0
End If
Next x
End With
The result is accurate as far as the math goes but my data range can have a value that extends to four decimal places which I have to truncate to two decimal places which can change the value of the sum and that new value is not reflected in my sum with the code I'm using because it only enters the value of the sum and not the formula for the sum. With that I'm not sure if it would be easier to round to the two decimal places before I run the code above or to try and make the change I'm looking for in the code.
I defer to you experts for advise.
Thanks.