Excel VBA Macro: Delete Rows (Based on List of Values)

Excel VBA Macro: Delete Rows (Based on List of Values)
💥Subscribe: / @greggowaffles
Code:
Sub delete_rows_based_on_list()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim row_count1 As Long
Dim row_count2 As Long
Dim i As Long
Dim j As Long
Set ws1 = ThisWorkbook.Sheets("Stock Screener")
Set ws2 = ThisWorkbook.Sheets("Items to Delete")
ws2.Activate
row_count2 = ws2.Cells(Rows.Count, "A").End(xlUp).Row
ws1.Activate
row_count1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row
For j = 1 To row_count2
i = 2
Do While i <= row_count1
If Cells(i, 10) = ws2.Cells(j, 1).Text Then
Rows(i).EntireRow.Delete
i = i - 1
row_count1 = row_count1 - 1
End If
i = i + 1
Loop
Next j
End Sub
#excelmacro #excelvba

Пікірлер: 6

  • @alexrosen8762
    @alexrosen87624 ай бұрын

    Your tutorials are really great and super useful 👌I can see a lot of use cases for this specific example in a lot of real world scenarios

  • @greggowaffles

    @greggowaffles

    4 ай бұрын

    Thanks! Appreciate the feedback as always!!

  • @Dexter101x
    @Dexter101x4 ай бұрын

    Oh you're back

  • @greggowaffles

    @greggowaffles

    2 ай бұрын

    😎😎

  • @justlooking717
    @justlooking7173 ай бұрын

    I tried using the code in your tutorial with a data table I am working with and did not work. This is my first attempt at using a macro to automate anything in excel so I am sure I am doing something wrong. I tried running in step and it highlights the Sub line. The table I am working with has order entries each listing the operations associated with these orders. Several operations in some orders do not have a scheduled start date, which is essential for the project I am doing so I need to delete the rows missing the start date and any operations associated with the order that had a "defective" operation. From your video I got the impression that your script would do this task but I can't make it work. Any advice?

Келесі