Error when looping on files

mikejvir

Board Regular
Joined
Jan 3, 2008
Messages
95
Hello,

I have a macro that does plotting on a group of files. But if the file has a particular word "[VERISION]" I need to skip it. I wrote the following that is within a loop for the files:

Code:
ActiveSheet.Cells(1, 1).Select
On Error GoTo GoodFile:
    Cells.Find(What:="[VERSION]", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
BadFile:
    itmp = MsgBox("File -" & FileName & "is Version 2" & Chr$(13) & " and cannot plot.", vbOKOnly, "Incorrect file type")
    GoTo FileEnd:

If I only do one file this works. One I select multiple files I get the following error dialog box:


Run-time error '91':

Object variable or with block variable not set


Not sure what I am doing wrong.

Thanks for the help in advance.

Michael Virostko
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Michael

Not sure about the rest of the code but perhaps you could use something like this to check for '[VERSION]'.
Code:
ActiveSheet.Cells(1, 1).Select

Set rngFnd =  Cells.Find(What:="[VERSION]", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

If Not rngFnd Is Nothing Then
    itmp = MsgBox("File -" & FileName & "is Version 2" & Chr$(13) & " and cannot plot.", vbOKOnly, "Incorrect file type")
    GoTo FileEnd
End If

PS Where are you looking for [VERSION]?
 
Upvote 0
Hello Norie,

I have been tied up. Your code worked great. Thanks.

Now I have a really weird issue and I probably should open a new question.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top