View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Problem with a loop and column references

Sub SumMyColsGarry()
' Totals each col in sets of grouped cols
Dim n&, lRow&

For n = Range("AB9").Column To Range("CK9").Column
lRow = WorksheetFunction.CountA(Columns(n))

If lRow 0 Then _
Cells(Rows.Count, n).End(xlUp)(3) =
WorksheetFunction.Sum(Columns(n))

Next 'n
End Sub


If rows are contiguous then and you want to place the sum 3 rows below
then...

If lRow 0 Then _
Cells(lRow + 3, n) = WorksheetFunction.Sum(Columns(n))

...works as well without the extra processing!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion