Error when looping on files

mikejvir

Board Regular
Joined
Jan 3, 2008
Messages
88
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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,216,081
Messages
6,128,694
Members
449,464
Latest member
againofsoul

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