Have the following code to sum a chaning range of values. Works fine except, excel always rounds the decimal up or down regardless if its ,2 or ,5. Always makes so that the sum end in a nice even ,0. Is there something in the code or is there a general excel preference that ive missed?
Cannot post the sheet as I am working on a mac. Here is the code though:
Sub GetTotals2()
Dim FloorStart As Integer, LastRow As Integer, FloorFinish As Integer, iCol As Byte
Dim FloorArea As Long
LastRow = Worksheets("Med LGH namn").Cells(Rows.Count, 1).End(xlUp).Row - 5
FloorStart = 4
FloorFinish = 4
FloorArea = 0
Do Until FloorStart = LastRow
Do Until Cells(FloorStart, 1) <> ""
FloorStart = FloorStart + 1
Loop
FloorFinish = FloorStart
Do Until Cells(FloorFinish + 1, 1) <> ""
FloorFinish = FloorFinish + 1
Loop
For iCol = 3 To 11 Step 2
FloorArea = FloorArea + WorksheetFunction.Sum(Range(Cells(FloorStart, iCol), Cells(FloorFinish, iCol)))
Next iCol
Range("L" & FloorFinish) = FloorArea
FloorArea = 0
FloorStart = FloorFinish + 1
Loop
Cells(FloorFinish + 4, 12) = WorksheetFunction.Sum(Range("L2", "L" & FloorFinish))
End Sub
Would be grateful if someone would help me get my boss off my back =)
Cannot post the sheet as I am working on a mac. Here is the code though:
Sub GetTotals2()
Dim FloorStart As Integer, LastRow As Integer, FloorFinish As Integer, iCol As Byte
Dim FloorArea As Long
LastRow = Worksheets("Med LGH namn").Cells(Rows.Count, 1).End(xlUp).Row - 5
FloorStart = 4
FloorFinish = 4
FloorArea = 0
Do Until FloorStart = LastRow
Do Until Cells(FloorStart, 1) <> ""
FloorStart = FloorStart + 1
Loop
FloorFinish = FloorStart
Do Until Cells(FloorFinish + 1, 1) <> ""
FloorFinish = FloorFinish + 1
Loop
For iCol = 3 To 11 Step 2
FloorArea = FloorArea + WorksheetFunction.Sum(Range(Cells(FloorStart, iCol), Cells(FloorFinish, iCol)))
Next iCol
Range("L" & FloorFinish) = FloorArea
FloorArea = 0
FloorStart = FloorFinish + 1
Loop
Cells(FloorFinish + 4, 12) = WorksheetFunction.Sum(Range("L2", "L" & FloorFinish))
End Sub
Would be grateful if someone would help me get my boss off my back =)