I get this error message (I hope I have translated it correctly from German to English) when running the following code:
It looks as if the Blockvariable is set. The interesting point is, that the error occurs when getting col1, not lastcol. I do not really see a difference between requesting lastcol and col1. col1 and row1 have been used and initialized previously. When debugging I also notice that the lastcol variable already has the correct value.
Code:
On Error Resume Next
oExl.Workbooks.Open filename
If Err > 0 Then
MsgBox "Could not open Excel file.", vbExclamation, "Fileerror"
Exit Sub
End If
On Error Goto 0
With oExl.ActiveWorkbook.Worksheets(1)
lastcol = CInt(.Cells.Find(What:="*", After:=.Cells(1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column)
lastrow = CInt(.Cells.Find(What:="*", After:=.Cells(1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Row)
col1 = CInt(.Cells.Find(str4, LookIn:=xlValues).Column)
row1 = CInt(.Cells.Find(str4, LookIn:=xlValues).Row)
It looks as if the Blockvariable is set. The interesting point is, that the error occurs when getting col1, not lastcol. I do not really see a difference between requesting lastcol and col1. col1 and row1 have been used and initialized previously. When debugging I also notice that the lastcol variable already has the correct value.