I would like someone to amend my code so that if sheets(2) does not exit tto open sheets(1)
Your asistance is most appreciated
Your asistance is most appreciated
Code:
With nb.Sheets(2)
Code:
Sub Import()
Dim LR As Long
'
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim nb As Workbook, ts As Worksheet, A As Variant
Dim rngDestination As Range
Sheets(2).Select
Set ts = ActiveSheet
On Error Resume Next
Set rngDestination = ts.[a1]
On Error GoTo 0
If rngDestination Is Nothing Then Exit Sub
ChDir ("C:\My Documents")
MsgBox "90206 will be imported"
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = "C:\My Documents\*Statement*.xlsx"
If .Show = 0 Then Exit Sub
A = .SelectedItems(1)
End With
Application.ScreenUpdating = False
Set nb = Workbooks.Open(A)
ThisWorkbook.Activate
With nb.Sheets(2)
LR = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("$A$1:$G$" & LR).AutoFilter Field:=4, Criteria1:="882786"
.UsedRange.SpecialCells(xlCellTypeVisible).Copy
End With
rngDestination.PasteSpecial Paste:=xlPasteValues
rngDestination.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
nb.Close savechanges:=False
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub