Excel VBA Macro: Delete Rows (Based on List of Values)
Вставка
- Опубліковано 10 лют 2025
- 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
Oh you're back
😎😎
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
Thanks! Appreciate the feedback as always!!
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?
Hey! Apologies for the late response. Hope you were able to figure it out, but if not, you can try this video to delete only rows with missing dates and then work up from there: ua-cam.com/video/Waa7Ew2n6T0/v-deo.htmlsi=Sc7T1R2SJIuj-Ww8 hope it helps!
Did not work, two thumbs way down
Sorry to hear it didn't work for you! Could you share a bit more detail about the issue you're experiencing? I'd be happy to help troubleshoot and see if we can get it working. Appreciate your feedback