programmation vba – supprime toute la rangée, ne contenant pas

Je suis nouveau dans les macros et les VBA, donc ça pourrait être facile.

J'ai besoin de filterr une list d'entresockets, de sorte que les entresockets qui ne correspondent pas à branchcode sont supprimées de l'onglet Excel.

Plus précisément:

  • company.xls contient la list complète des entresockets, où la colonne N contient des codes succursales
  • branch.xls, la colonne A contient les codes de dérivation pertinents, qui doivent être utilisés pour filterr les comapnies dans company.xls
  • Les entresockets en company.xls qui n'ont pas de correspondance
    Branchcode devrait être supprimé de tab1 à tab2 de company.xls.

J'espère que ça a du sens!?

Merci d'avance pour vos réponses.

Function Search_Ssortingng(x As Ssortingng) As Boolean Dim Firstrow As Long Dim Lastrow As Long Dim Lrow As Long Dim Contained As Boolean Contained = True 'We use the ActiveSheet but you can replace this with 'Sheets("MySheet")if you want With Sheets("codes") 'We select the sheet so we can change the window view .Select 'Set the first and last row to loop through Firstrow = .UsedRange.Cells(1).Row Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row 'We loop from Lastrow to Firstrow (bottom to top) For Lrow = Lastrow To Firstrow Step -1 'We check the values in the A column in this example With .Cells(Lrow, "A") 'Column letter for codes sheet If Not IsError(.Value) Then If InStr(x, .Value) Then Contained = False End If End With Next Lrow End With Search_Ssortingng = Contained End Function Sub Filtrer() Dim Firstrow As Long Dim Lastrow As Long Dim Lrow As Long Dim CalcMode As Long Dim ViewMode As Long With Application CalcMode = .Calculation .Calculation = xlCalculationManual .ScreenUpdating = False End With With Sheets("search (14)") 'Sheet name with rows to be deleted 'We select the sheet so we can change the window view .Select 'If you are in Page Break Preview Or Page Layout view go 'back to normal view, we do this for speed ViewMode = ActiveWindow.View ActiveWindow.View = xlNormalView 'Turn off Page Breaks, we do this for speed .DisplayPageBreaks = False 'Set the first and last row to loop through Firstrow = .UsedRange.Cells(1).Row Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row 'We loop from Lastrow to Firstrow (bottom to top) For Lrow = Lastrow To Firstrow Step -1 With .Cells(Lrow, "N") 'Change this to the correct Sheets column that needs deleting If Not IsError(.Value) Then If Search_Ssortingng(.Value) Then .EntireRow.Delete End If End With Next Lrow End With ActiveWindow.View = ViewMode With Application .ScreenUpdating = True .Calculation = CalcMode End With End Sub 

Corrigez-moi si je me trompe. Maintenant, vous voulez laisser l'user entrer le nom de la feuille et le nom de la colonne

Ensuite, le code suivant vous aidera.

 Dim SheetName As Ssortingng Dim ColumnName As Ssortingng SheetName = InputBox("Enter the Sheet Name ?") ' Ex Sheet1 ColumnName = InputBox("Enter the column Name ?") ' Ex N With Sheets(SheetName) ' Replace this line With .Cells(Lrow, ColumnName) ' Replace this line