Kennypowers55
New Member
- Joined
- Nov 20, 2022
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
I have a big dataset that I'd like to clean up.
I want to do it by having a list in sheet2 of words, that is used to delete entire rows in sheet1.
I found one thread that answers this only if it's an exact match. Where the cell could only contain "lean" to be deleted.
I want it to delete based on a word in a sentence or mix of words.
For example delete a row containing a cell with the sentence "What is lean", based on having "lean" in the list in sheet2.
Hilfe hilfe
The other thread
The VBA Code:
Code:
Sub delrows()
Dim d As Object, e, rws&, cls&, i&, j&
Set d = CreateObject("scripting.dictionary")
For Each e In Sheets("sheet2").Range("A1").CurrentRegion
d(e.Value) = 1
Next e
Sheets("sheet1").Activate
rws = Cells.Find("*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
cls = Cells.Find("*", after:=[a1], searchorder:=xlByColumns, _
searchdirection:=xlPrevious).Column
For i = rws To 1 Step -1
For j = 1 To cls
If d(Range("A1").Resize(rws, cls)(i, j).Value) = 1 Then _
Cells.Rows(i).Delete: Exit For
Next j, i
End Sub
I want to do it by having a list in sheet2 of words, that is used to delete entire rows in sheet1.
I found one thread that answers this only if it's an exact match. Where the cell could only contain "lean" to be deleted.
I want it to delete based on a word in a sentence or mix of words.
For example delete a row containing a cell with the sentence "What is lean", based on having "lean" in the list in sheet2.
Hilfe hilfe
The other thread
VBA - Delete entire row based on a list of values on a separate sheet
Hello, I copy and paste a table "Customer" from a source to Sheet1 in excel. I would like delete the entire row in the "Customer" table if it contains/matches values from a list in Sheet2. I wonder if anyone has a VBA code that enable me to automate that process. Thank you!
www.mrexcel.com
The VBA Code:
Code:
Sub delrows()
Dim d As Object, e, rws&, cls&, i&, j&
Set d = CreateObject("scripting.dictionary")
For Each e In Sheets("sheet2").Range("A1").CurrentRegion
d(e.Value) = 1
Next e
Sheets("sheet1").Activate
rws = Cells.Find("*", after:=[a1], searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
cls = Cells.Find("*", after:=[a1], searchorder:=xlByColumns, _
searchdirection:=xlPrevious).Column
For i = rws To 1 Step -1
For j = 1 To cls
If d(Range("A1").Resize(rws, cls)(i, j).Value) = 1 Then _
Cells.Rows(i).Delete: Exit For
Next j, i
End Sub