Abord sub if criteria is not met

AlexSrois

New Member
Joined
Aug 14, 2021
Messages
18
Office Version
  1. 2016
Platform
  1. Windows
Hi guys! Need your help!

I've got a macro that :
1) Select all the rows from a table when the A value is ''Complété''
2) Copy these rows to another worksheet
3) Delete theses rows from the first table

My sub is working perfectly, execepted that if there is no value that meets the criteria (''complété''), then it deletes everything. I'm pretty sure you can see why this is a problem ;)

How can I make the sub to abord itself if the criteria isn't met?

Here is my sub ;
VBA Code:
Sub Archive()

' Copy Completed task value from WorksheetPanier to WorksheetArchives

Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet

    Sheets("Panier").Select
   ActiveSheet.ListObjects("Panier").Range.AutoFilter Field:=1, Criteria1:= _
        "Complété"
    Range("Panier").Select
    Selection.Copy
  
  Set copySheet = Worksheets("Panier")
  Set pasteSheet = Worksheets("Archives")

  pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
  
' Go back and delete Completed task
  
    Sheets("Panier").Select
    Application.CutCopyMode = False
    Selection.EntireRow.Delete
    ActiveSheet.ListObjects("Panier").Range.AutoFilter Field:=1
     
' End routine

    ThisWorkbook.Save
    ActiveWorkbook.RefreshAll
    
End Sub
 
No problems, I am happy to help! Thanks again for the feedback.
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,214,885
Messages
6,122,090
Members
449,065
Latest member
Danger_SF

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