VBA Excel循环协助

时间:2014-06-04 21:24:06

标签: excel vba excel-vba

将此转变为for循环的任何帮助将不胜感激。我列出了G列和H列,但需要它去AA。

此致

Sub AutoSum()  
Dim Area As Range, MyColumn As String    
MyColumn = "G"    
    For Each Area In Columns(MyColumn).SpecialCells(xlConstants, xlNumbers).Areas    
        SumAddr = Area.Address(False, False)    
        Area.Offset(Area.Count, 0).Resize(1, 1).Formula = "=SUM(" & SumAddr & ")"    
    Next Area    
MyColumn = "H"    
    For Each Area In Columns(MyColumn).SpecialCells(xlConstants, xlNumbers).Areas    
        SumAddr = Area.Address(False, False)    
        Area.Offset(Area.Count, 0).Resize(1, 1).Formula = "=SUM(" & SumAddr & ")"    
    Next Area    
End Sub

1 个答案:

答案 0 :(得分:0)

  

对于c = 7到8' G到H

 For Each Area In Columns(c).SpecialCells(xlConstants, xlNumbers).Areas
     SumAddr = Area.Address(False, False)
     Area.Offset(Area.Count, 0).Resize(1, 1).Formula = "=SUM(" & SumAddr & ")"
 Next Area
     

下一个c