У меня есть макрос для поиска значений в столбце b электронной таблицы в каталоге и копирования этих данных на рабочий лист.У меня проблема в том, что если один из файлов не существует, как мне заставить макрос пропустить это поле и перейти к следующему файлу, не прерывая макрос?
Данные столбца B: ABC DEF GHIJKL и т. Д.
Например, если DEF не найден в каталоге, как заставить макрос пропустить это поле и перейти к следующему?
Dim myStop As Long, x As Long, y As Long, myColumn As Long, myYear As Long
Dim myRev As Double, myTOTALlb As Double, myLabor As Double, myVacation As
Double
Dim myBranch As String, myFolder As String, myFile As String
Dim myBUDGETwb As Workbook, myBIEEwb As Workbook
Dim myRegion As Variant
'Application.ScreenUpdating = False
'Opens/Sets Budget workbook.
On Error Resume Next
Set myBIEEwb = ActiveWorkbook 'Workbooks("US BUDGET- REVENUES 2018.xlsx")
On Error GoTo 0
myYear = Right(Cells(3, 1), 4)
myFolder = "U:\Fy" & myYear & "\Final " & myYear & "\"
For x = 9 To 103
myRegion = Cells(x, 1)
myBranch = Cells(x, 2)
If myRegion = 0 Or myRegion = "" Then
GoTo NoRegion
Else
'Opens/Sets Budget workbook.
On Error Resume Next
Set myBUDGETwb = Workbooks("F" & myYear & "Budget" & myBranch & "*.xls*")
On Error GoTo 0
If myBUDGETwb Is Nothing Then
myFile = Dir(myFolder & "F" & myYear & "Budget" & myBranch & "*.xls*")
Set myBUDGETwb = Workbooks.Open(myFolder & myFile, UpdateLinks:=False)
End If
End If
myBUDGETwb.Worksheets("BudDetail").Activate
myColumn = Range(Range("A7"), Range("A7").End(xlToRight)).Columns.Count - 1
myRev = Cells(Cells.Find("Net Textile Rental Rev", SearchOrder:=xlByRows,
searchdirection:=xlNext).Row, myColumn) + _
Cells(Cells.Find("Net Product Sales", SearchOrder:=xlByRows,
searchdirection:=xlPrevious).Row, myColumn)
For y = 21 To 300
If InStr(1, Cells(y, 1), "LABOR") > 0 Or InStr(1, Cells(y, 1), "SALES
COMMISSION") > 0 Then
myLabor = myLabor + Cells(y, myColumn)
GoTo FoundIt
End If
If InStr(1, Cells(y, 1), "VACATION") > 0 Then
myVacation = myVacation + Cells(y, myColumn)
GoTo FoundIt
End If
FoundIt:
Next y
myTOTALlb = myLabor + myVacation
myBIEEwb.Activate
Cells(x, 4) = myRev
Cells(x, 5) = myTOTALlb
myRev = 0
myLabor = 0
myVacation = 0
myTOTALlb = 0
myBUDGETwb.Close False
Set myBUDGETwb = Nothing
Cells(x, 2).Interior.Color = 5287936
NoRegion:
Next x
Application.ScreenUpdating = True
End Sub
любая помощь будетоценили.