View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Bill Pfister Bill Pfister is offline
external usenet poster
 
Posts: 132
Default Stepping through gives different result than running

I have also had issues when I alter the visibility (hidding or grouping) of
rows/columns just before using find. I don't see any reason to think this is
the case here, but it is something to keep in mind while using Find in a
macro.


"Gregg Roberts" wrote:

[Anyone else having trouble getting the page to come back with content in the
main pane after logging in?]

Thanks to all for your quick replies. Responses below.

Look for references like
Range("A1")
this refers to the activesheet when stepping through your code. When
running your code, it refers to the sheet that contains the code. Put in
explicit references


I have a mixture of explicit and implicit references, but this code was
copied (then modified) from another sub that works fine. And, it works as
expected when stepping through without the problem you allude to. I've always
wondered why the problem you're alluding to doesn't happen all the time, but
it doesn't. Everything else works, mousing over the variables shows the
expected values, etc. However, I'll try what you suggest.

Same goes for the response about possible bottlenecking. There are almost as
many opportunities for that as there are lines of code, yet this is the only
place it's happening that I know of. I'm in Excel 2003, the data files are
CSV, but I save them as Excel after opening them and in some cases doing a
little sorting.

I'm also going to try the debug.print suggestion.

Here's the sub where the false alarm is occurring. The ErrText is getting
populated when it shouldn't. (It gets to "" after the only code line where it
gets written to an error file.)

----------------

Sub CheckCISEligibility()

Dim CEFindCell As Range
Dim curCEFileRow As Long

CFELIGTableFile.Activate
Range("B1").Select

<See, Tom, right there is an implicit reference, but it works even when I
step through...

Set CEFindCell = ActiveSheet.Range("B2:B65536").Find(CASEFILE_ID,
LookAt:=xlWhole)
If Not CEFindCell Is Nothing Then
curCEFileRow = CEFindCell.Row
Do
If Cells(curCEFileRow, 3) = "1" Then ' ANOTHER IMPLICIT REFERENCE
CIS_Eligible = True
End If
curCEFileRow = curCEFileRow + 1
Loop Until CIS_Eligible Or Cells(curCEFileRow, 2) < Cells(curCEFileRow
- 1, 2)
Else
ErrText = ErrText & "CIS Eligibility not indicated" & Chr(10)
Debug.Print "CASEFILE_ID = " & CASEFILE_ID & ", CIS Eligibility not
indicated"
End If

Set CEFindCell = Nothing

End Sub