Excel VBA Macro: Delete Rows (Based on Cell Values in Multiple Columns)

  Рет қаралды 2,806

greggowaffles

greggowaffles

Жыл бұрын

Excel VBA Macro: Delete Rows (Based on Cell Values in Multiple Columns)
💥Subscribe: / @greggowaffles
Code:
Sub delete_rows_based_on_multi_col()
Dim row_count As Long
Dim i As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Countries")
ws.Activate
row_count = ws.Cells(Rows.count, "A").End(xlUp).Row
i = 2
Do While i <= row_count
If Cells(i, 6) = "" _
Or Cells(i, 10) = "" _
Or Cells(i, 5) > 10000 Then
Rows(i).EntireRow.Delete
i = i - 1
row_count = row_count - 1
End If
i = i + 1
Loop
End Sub
#excelmacro #excelvba

Пікірлер: 15
@ItsTyara
@ItsTyara 5 ай бұрын
You are amazing!!!!!! Thank you!! Quick Question. I want to delete duplicates. What code do I type to delete duplicates? If Cells(i,1).Value > 1 ??
@sakhilengwenya594
@sakhilengwenya594 Ай бұрын
Is there a reason why didn’t you do a For loop, this looks complicated
@josea.pascualr.4779
@josea.pascualr.4779 Жыл бұрын
I want to do something similar to this... I have some records and I there's a column that may contain duplicate values and I want that based on a value that is on another column delete one specific row from my duplicates, meaning I just want to keep one specific row based on the values that column F (duplicate values) and column B (what determinates which row I have to delete). For example I have: Row 1, Column B value = 0, Column F value = 123456 Row 2 ,Column B value = 1, Column F value = 123456 Based on that example I want to delete rows where my Column F value is duplicate and the column B value is 1. In that case Row 2 must be deleted and Row 1 needs to stay. Is there any way of doing this using VBA?
@SMJ0192
@SMJ0192 Жыл бұрын
nice
@greggowaffles
@greggowaffles Жыл бұрын
Thanks!
@deepk82
@deepk82 4 ай бұрын
Why did we give i,6 or i,10 ? Cant we give just a universal condition for the entire row?
@greggowaffles
@greggowaffles 4 ай бұрын
That’s a good point. I’ll make a video on this scenario
@SMJ0192
@SMJ0192 Жыл бұрын
Can I loop it where the cells check against other cells on another worksheet and remove the rows from the first worksheet?
@greggowaffles
@greggowaffles Жыл бұрын
Yeah. So based on values in a list on another worksheet?
@SMJ0192
@SMJ0192 Жыл бұрын
@@greggowaffles yes essentially i have two worksheets and one contains a list of discontinued items with a code. I want to remove the items on sheet1 that have a code in sheet2 (if the discontinued code matches)
@greggowaffles
@greggowaffles Жыл бұрын
@@SMJ0192 cool. I’ll have a video on this by Sunday
@SMJ0192
@SMJ0192 Жыл бұрын
@@greggowaffles Awesome, I look forward to it. Thanks for getting back to me!
@greggowaffles
@greggowaffles Жыл бұрын
@@SMJ0192 hey sorry i havent dropped the video yet but heres the 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("sheet1") Set ws2 = ThisWorkbook.Sheets("sheet2") 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
Excel VBA Macro: Delete Rows (Based on List of Values)
12:22
greggowaffles
Рет қаралды 606
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 25 МЛН
Inside Out Babies (Inside Out Animation)
00:21
FASH
Рет қаралды 13 МЛН
VBA Macro to Delete Rows Based on Cell Values
9:32
Excel Campus - Jon
Рет қаралды 139 М.
VBA to Delete Multiple Columns based on Headers - Excel VBA Macro Example
8:45
How to Get List of File Names in a Folder using Excel
5:40
Excel Weez
Рет қаралды 6 М.
Excel VBA Macro: Delete Rows Faster (Based on Cell Value)
17:18
greggowaffles
Рет қаралды 7 М.
How to get the Last Row in VBA(The Right Way!)
15:41
Excel Macro Mastery
Рет қаралды 154 М.
Delete Rows Based On Criteria Excel VBA Macro
6:39
Excel Macro Mania
Рет қаралды 43 М.
Delete Rows based on Value/Text // Excel VBA Tutorial
8:53
Data Nik
Рет қаралды 19 М.
Excel VBA Macro: Delete Rows Based on Cell Value (Zeros and Blanks)
5:51
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 25 МЛН