VBA sum up values

Strooprover

New Member
Joined
Jul 21, 2017
Messages
25
Hi all,

CostsCosts 2Total Costs
€15,00€0,00

<colgroup><col><col><col></colgroup><tbody>
</tbody>

I want to adjust my macro so it adds up the two costs in the totcal costs area. This has to be done fot a lot of rows. In between the rows in this column there are empty spaces. I made this formula, but when I use the sum formula it says: €15,00€0,00 in the total costs area.

Can someone help me?
Code:
Sub Macro1()
Dim ws2 As worksheet
Set ws2 = Sheets("Sheet2")




Dim kosten As String
totkosten = ws2.Range("E2").Value


i = 1
For x = 1 To 1000


keer = Range("F" & i).Value


If ws2.Cells(x, 5) = totkosten Then
ws2.Cells(x, 5).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Range("A1:A" & keer).Value = ActiveCell.Offset(0, -2).Value + ActiveCell.Offset(0, -1).Value


i = i + 1
End If


Next x






End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hia
Give this a go
Code:
With ActiveCell
    .Range("A1:A" & keer).Value = WorksheetFunction.Sum(.Offset(, -2), .Offset(, -1))
End With
 
Last edited:
Upvote 0
Assuming the costs are in column C and D and you want the total in E then this should work

Code:
Sub sumtotal()
Dim lr As Long
Dim ws2 As Worksheet
Set ws2 = Sheets("Sheet2")
lr = ws2.Cells(Rows.Count, 3).End(xlUp).Row
For x = 2 To lr
    If Cells(x, 3) <> "" Then
        Cells(x, 5) = Cells(x, 3) + Cells(x, 4)
    End If
Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,135
Messages
6,123,241
Members
449,093
Latest member
Vincent Khandagale

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