Hey All,
I'm getting the error that no cells have been found when running the following code. Although it is correct and no cells have been found under the criteria I've put, I want the code to just move on and continue with the code. Could anyone help me to do this? I am a beginner when it comes to VBA so if you have any other suggestions as to how my code could be more efficient feel free to say too. Any help would be appreciated and thank you in advance. My code is below.
I'm getting the error that no cells have been found when running the following code. Although it is correct and no cells have been found under the criteria I've put, I want the code to just move on and continue with the code. Could anyone help me to do this? I am a beginner when it comes to VBA so if you have any other suggestions as to how my code could be more efficient feel free to say too. Any help would be appreciated and thank you in advance. My code is below.
VBA Code:
Option Explicit
Sub Contractors()
Workbooks.Open ("C:\Users\ImaniS\OneDrive - Vodafone Group\Documents\Declaration Template\2022 Renewal Data\03. Property Damage & Business Interruption\3.5 Contractors All Risks.xlsx")
Dim lr1 As Long
Dim lr2 As Long
With Workbooks("3.5 Contractors All Risks.xlsx").Sheets("Sheet1")
lr1 = .Cells(Rows.Count, 1).End(xlUp).Row
.AutoFilterMode = False
.Range("A1:AY" & lr1).AutoFilter Field:=1, Criteria1:="GR01" 'filter range on EVO Code
lr2 = Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Cells(Rows.Count, 1).End(xlUp).Row + 1
.Range("G9:H" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("A41").PasteSpecial xlPasteAll 'Copy/Paste
.Range("K9:L" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("C41").PasteSpecial xlPasteAll
.Range("N9:S" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("E41").PasteSpecial xlPasteAll
.AutoFilterMode = False
End With
Application.CutCopyMode = False
Workbooks("3.5 Contractors All Risks.xlsx").Close
Workbooks.Open ("C:\Users\ImaniS\OneDrive - Vodafone Group\Documents\Declaration Template\2022 Renewal Data\01. Vodafone Information\1.5 Business Activities.xlsx")
With Workbooks("1.5 Business Activities.xlsx").Sheets("Sheet1")
.AutoFilterMode = False
.Range("A1:AY" & lr1).AutoFilter Field:=1, Criteria1:="GR01" 'filter range on EVO Code
.Range("A9:A" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B10").PasteSpecial Paste:=xlPasteAll 'Copy/Paste
.Range("B9:B" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B11").PasteSpecial Paste:=xlPasteAll
.Range("C9:C" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B12").PasteSpecial Paste:=xlPasteAll
.Range("F9:F" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B13").PasteSpecial Paste:=xlPasteAll
.Range("H9:H" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B14").PasteSpecial Paste:=xlPasteAll
.Range("I9:I" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B15").PasteSpecial xlPasteAll
.Range("J9:J" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B16").PasteSpecial xlPasteAll
.Range("K9:K" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B19").PasteSpecial xlPasteAll
.Range("L9:L" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B20").PasteSpecial xlPasteAll
.Range("M9:M" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B21").PasteSpecial xlPasteAll
.Range("O9:O" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B22").PasteSpecial xlPasteAll
.Range("P9:P" & lr1).SpecialCells(xlCellTypeVisible).Copy
Workbooks("Declaration_Template.xlsm").Sheets("TEMP").Range("B23").PasteSpecial xlPasteAll
.AutoFilterMode = False
End With
Application.CutCopyMode = False
Workbooks("1.5 Business Activities.xlsx").Close
End Sub