2016-11-18 48 views
0

希望你能幫助我。我有大量的名單像這樣:儘管通過列循環創建總和

example

我所需要的一切的自動求和,上面是灰色行。

到目前爲止我的代碼:

Dim source As Range 
Dim iCol As Long 
Dim nCol As Long 
Dim Cell As Range 

Set source = Selection 

For iCol = 1 To 5 

With source.Columns(iCol) 

If Cell.Font.Bold = False Then 
i = i + Cell.Value 

Else: Cell.Value = i 
i = 0 


End If 

End With 
Next iCol 

提前感謝!

回答

0

我相信這是你以後

Dim source As Range, col As Range, cell As Range 
Dim res As Double 

Set source = Selection 

With source 
    For Each col In .Columns 
     For Each cell In col.Cells 
      If cell.Font.Bold Then 
       cell.Value = res 
       res = 0 
      Else 
       res = res + cell.Value 
      End If 
     Next cell 
    Next col 
End With 
+0

完美,這正是我了!謝謝:) – Urumita

+0

不客氣。你可能想接受答案。謝謝! – user3598756