2017-02-07 42 views
-1

我需要一个算法,使三个单元格的总和,并把它放在第三个单元格,并重复相同的事情为该行的其余部分。算法,使三行的总和excel-vba

The table i want to have algorithm with code vba

With ws  
    i = .Range("AC9").End(xlDown).Row 
    cumul = 0 

    .Range("AF9").Value = Application.WorksheetFunction.Sum(.Range("AC9:AC" & i))  
End With 
+0

你做了什么? – Kasnady

+0

我使用此代码但不工作“带有WS I = .Range( “AC9”)。完(xlDown).Row cumul = 0 .Range( “AF9”)。值= Application.WorksheetFunction。 Sum(.Range(“AC9:AC”&i)) End With' – Houyam

+0

向我们显示您的代码@Houyam – Kasnady

回答

2

试试这个

Sub sums() 
    Dim cell As Range 

    With Worksheets("mySheetname") '<--| change "mySheetname" to your actual sheet name 
     For Each cell In .Range("A2", .Cells(.Rows.count, "A").End(xlUp)) '<--| change "A" references to your actual "Poid_CFA" column index 
      cell.Offset(, 3).Value = WorksheetFunction.Sum(cell.Resize(, 3)) 
     Next 
    End With 
End Sub 
+0

非常感谢您 – Houyam

+0

欢迎您 – user3598756