View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Colleyville Alan Colleyville Alan is offline
external usenet poster
 
Posts: 11
Default Code works 1st time then Type Mismatch when checking for not blank cells

I have some VBA code writing info to a spreadsheet. At one point, I loop
from row 200 backwards looking for a row with text so that I can indicate
that this is the last row.
After I have written a bunch of text, this runs and everything is fine. But
then I add some more text and I get a "Type Mismatch" error.


For n = 200 To 1 Step -1
If oxlWks.Worksheets("Sheet1").Range("B" & n) Or
oxlWks.Worksheets("Sheet1").Range("A" & n) < "" Then
ilastrow = n
Exit For
End If
Next n

As I say, it goes thru fine but the next time I run it, it crashes on the
line that checks for a not empty condition. The text is bold but that is
the only difference between the type of text that was there the first time
through. How in the world do I get a "Type Mismatch"? I have looked at a
watch window and it shows just what I see on the spreadsheet. I know a
crude work-around, but this is bugging me.

Thanks

p.s. if there is a lastrow function in Excel, fine. But I still want to
know why this does not work.