In my workbook, the VBA code writes SUMIF functions properly, then I use the FillRight property to drag the generated equations to the right. The problem is that, in the real data, sometimes the cells that would get the SUMIF function already have data themselves that needs to be included. Clearly, dragging the formula across will obliterate that data. I thought that I could write the VBA code to retain any existing data along with the SUMIF function, but instead of dragging it to the right I would have Excel simply write the function across using a different index key for the number of columns.

My question is, right now my code has the following:

- For i = 1 To WBSLevel
- Range("A3").Select
- Do
- If (ActiveCell.Value = i And IsEmpty(ActiveCell.Offset(0, 7)) And ActiveCell.Offset(1, 0) <> "NO MORE") = True Then
- begin = ActiveCell.Row
- ActiveCell.Offset(1, 0).Select
- Do
- If (ActiveCell.Value = i) = False Then
- ActiveCell.Offset(1, 0).Select
- ElseIf ((ActiveCell.Value = i) And (ActiveCell.Offset(1, 0).Value = "NO MORE")) = True Then
- endlevel = ActiveCell.Row
- ElseIf (ActiveCell.Value = "NO MORE") = True Then
- endlevel = ActiveCell.Row - 1
- End If
- Loop Until ((ActiveCell.Value = i) Or (ActiveCell.Offset(1, 1) = "NO MORE") Or (ActiveCell.Offset(0, 1) = "NO MORE")) = True
- endlevel = ActiveCell.Row - 1
- Cells(begin, 9).Formula = "=sumif($A" & begin + 1 & ":$A" & endlevel & "," & i + 1 & ",I" & begin + 1 & ":I" & endlevel & ")"
- Range(Cells(begin, 9), Cells(begin, 9 + years - 1)).FillRight
- Else
- ActiveCell.Offset(1, 0).Select
- End If
- Loop Until ActiveCell.Row > endthis
- Next i

I can hardcode Column I as the starting point because the first year will always be put in that column. I know I can insert a new index, say j, before the SUMIF function and write that function for each column that needs it, but how would I rewrite the code? The Column() function returns the column number; is there a function whose argument is the column number and will return the letter? I would like to have the function look something like:

Of course, the ...FillRight command would go away.

Any ideas? Thanks in advance. ozgrid.com/forum/core/index.php?attachment/36952/