View Single Post
  #2   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

Are the rows in each group contiguous? If so you just need to find the
last data row (sound familiar?) and exit the loop at the 1st empty
value.

OR

Use an array's 2nd dim to determine where empty cols are and where last
data row is for each col of UsedRange.

OR

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

For n = Range("AB1").Column To Range("CK1").Column
lRow = WorksheetFunction.CountA(Columns(n))
If lRow 0 Then _
Cells(lRow + 1, n) = WorksheetFunction.Sum(Columns(n))
Next 'n
End Sub

--
Garry

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