VBA - Excel help

bythesea
03-26-2003, 07:16 AM
can someone advise me on what's wrong with the following sample codes?

thnx in advance.

private sub MethodA()

while

..........call MethodB(iterator, wksheet)

wend

end sub

private Sub MethodB(a As CListIterator, ws As Excel.worksheet)

Dim flag As Boolean
flag = True

While a.HasMoreItems And flag
If ws.Cells(2, i) <> "" Then <-------------highlighted error
If a.CurrStep = ws.Cells(2, i) Then
ws.Cells(4, i) = a.CurrQuantity
i = 3
a.MoveOn
Else
i = i + 1
End If
Else
flag = False
End If
Wend


End Sub

im very sure the while loop in MethodB was able to execute smoothly. the
problem comes after several iterations when the following errr message appears
as indicated in the highlighted line above:

"Run-time error '91'

Object variable or With Block variable not set"

if i do not have any problem for the first 20-40 iterations, why does the
error occur now?

i have been stuck for a few hours and would appreciate any advice or guidance.

thanks

note: MethodB is the exact set of codes im using in my program

jbo
04-05-2003, 02:13 PM
It looks like a classic algorithm problem.

The variable i is used to iterate through columns.
Do you know that a worksheet is limited to 256 columns?

If i>256 then an error occurs.
Please, debug to test i value.

Iceplug
04-05-2003, 07:30 PM
Do you ever set the wksheet that you pass to methodB = New Excel.Worksheet or existing worksheet?
Set wkSheet = New Excel.Worksheet
or
Set wkSheet = wkBook.Worksheets(1)?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum