To learn recursive programming and trying to write a simple VBA to traverse to every cell in a defined range and put 1 into the cells. (I know this can be done easily through iteration by using two loops.)
The following script fills up to 3346 cells before it threw Error 28 "Out of Stack spaces".
Is it an error on my script or Excel's limit on stack?Thank you for your help.
--Sub test() Dim L As String L = rWrite(Range("A1:Z300"), 1, 1, 1, Range("A1:Z300").Rows.Count, Range("A1:Z300").Columns.Count) End Sub Function rWrite(ByRef rArray As Range, iVal As Integer, CurRow As Integer, CurCol As Integer, RowsCount As Integer, ColsCount As Integer) As String If CurCol <= ColsCount Then If CurRow <= RowsCount Then rArray.Cells(CurRow, CurCol) = iVal rWrite = rWrite(rArray, iVal, CurRow + 1, CurCol, RowsCount, ColsCount) Else rWrite = rWrite(rArray, iVal, 1, CurCol + 1, RowsCount, ColsCount) End If Else rWrite = "Done" End If End Function
Chris Win
Last edited by itzchau; 11-11-2010 at 11:57 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks