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

  Рет қаралды 1,104

greggowaffles

greggowaffles

Күн бұрын

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
@alexrosen8762 7 ай бұрын
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 7 ай бұрын
Thanks! Appreciate the feedback as always!!
@Dexter101x
@Dexter101x 6 ай бұрын
Oh you're back
@greggowaffles
@greggowaffles 5 ай бұрын
😎😎
@justlooking717
@justlooking717 6 ай бұрын
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?
Кәсіпқой бокс | Жәнібек Әлімханұлы - Андрей Михайлович
48:57
Life hack 😂 Watermelon magic box! #shorts by Leisi Crazy
00:17
Leisi Crazy
Рет қаралды 80 МЛН
3 Essential Excel skills for the data analyst
18:02
Access Analytic
Рет қаралды 1,5 МЛН
Excel - COUNTIF Uses
15:11
TooManyHobbiesNotEnoughTime
Рет қаралды 47
AMBER 2024 API Run Multiple Vehicles using Saved Simulink Diagrams
17:09
Argonne Vehicle & Mobility Systems Group
Рет қаралды 21
How to Easily Create an Data Entry Form in Excel | No VBA
22:30
Jopa Excel
Рет қаралды 37 М.
Delete Rows Based On Criteria Excel VBA Macro
6:39
Excel Macro Mania
Рет қаралды 48 М.
How to Move Data Automatically Between Excel Files
11:37
Kenji Explains
Рет қаралды 154 М.