A
Ann
I am running the VBA below. It works great, but slow. I have 2000+ account
numbers that have to be looked for in 20 different files.
Currently, it works like this:
Opens File1, search for Acct #1, Close File1
Open File2, search for Acct#1, Close File2....
and so on, until it either finds the Acct # or has searched all the files.
Then it starts over, searching for Acct #2......it takes about 15 minutes to
run through 25 Acct #'s.
Is there a way to speed this up? Any ideas?
Thanks,
Ann
Sub AcNos()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim AcNo As String
Dim eAc As Long
Dim i As Long
Dim sh As Long
Dim fndAc As Range
On Error GoTo Errorhandler
Application.ScreenUpdating = False
eAc = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\Documents and Settings\zzfy98\My
Documents\Test") 'change directory
For i = 1 To eAc
AcNo = Sheets("Sheet1").Cells(i, 1).Value
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path _
& "\" & objFile.Name, UpdateLinks:=False
With Workbooks(objFile.Name)
For sh = 1 To .Sheets.Count
With .Sheets(sh).Cells
Set fndAc = .Find(AcNo _
, LookIn:=xlValues _
, Lookat:=xlPart _
, MatchCase:=True)
End With
If Not fndAc Is Nothing Then
ThisWorkbook.Sheets("Sheet1"). _
Cells(i, 2).Value = "Yes"
Exit For
End If
Next sh
.Close False
End With
Set objFile = Nothing
End If
Next
With Sheets("Sheet1").Cells(i, 2)
If .Value <> "Yes" Then .Value = "No"
End With
Next i
Errorhandler:
Application.ScreenUpdating = True
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
End Sub
numbers that have to be looked for in 20 different files.
Currently, it works like this:
Opens File1, search for Acct #1, Close File1
Open File2, search for Acct#1, Close File2....
and so on, until it either finds the Acct # or has searched all the files.
Then it starts over, searching for Acct #2......it takes about 15 minutes to
run through 25 Acct #'s.
Is there a way to speed this up? Any ideas?
Thanks,
Ann
Sub AcNos()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim AcNo As String
Dim eAc As Long
Dim i As Long
Dim sh As Long
Dim fndAc As Range
On Error GoTo Errorhandler
Application.ScreenUpdating = False
eAc = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\Documents and Settings\zzfy98\My
Documents\Test") 'change directory
For i = 1 To eAc
AcNo = Sheets("Sheet1").Cells(i, 1).Value
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path _
& "\" & objFile.Name, UpdateLinks:=False
With Workbooks(objFile.Name)
For sh = 1 To .Sheets.Count
With .Sheets(sh).Cells
Set fndAc = .Find(AcNo _
, LookIn:=xlValues _
, Lookat:=xlPart _
, MatchCase:=True)
End With
If Not fndAc Is Nothing Then
ThisWorkbook.Sheets("Sheet1"). _
Cells(i, 2).Value = "Yes"
Exit For
End If
Next sh
.Close False
End With
Set objFile = Nothing
End If
Next
With Sheets("Sheet1").Cells(i, 2)
If .Value <> "Yes" Then .Value = "No"
End With
Next i
Errorhandler:
Application.ScreenUpdating = True
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
End Sub