Baiano42
08-02-2019, 04:42 AM
Good morning,
I am trying to generate a macro that would auto set the range I use ("$A$1:$O$1000"), and give the user the option to input one or more criteria to search and delete rows for.
I found this code at https://www.extendoffice.com/documents/excel/1747-excel-delete-row-if-zero.html:
Sub DeleteRows()'Updateby20140314
Dim rng As Range
Dim InputRng As Range
Dim DeleteRng As Range
Dim DeleteStr As String
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
DeleteStr = Application.InputBox("Delete Text", xTitleId, Type:=2)
For Each rng In InputRng
If rng.Value = DeleteStr Then
If DeleteRng Is Nothing Then
Set DeleteRng = rng
Else
Set DeleteRng = Application.Union(DeleteRng, rng)
End If
End If
Next
DeleteRng.EntireRow.Delete
End Sub
The difference I need from it is to preset the specified range and loop through the "Delete Text" part until the user is satisfied and presses "Cancel".)
I also found a similar macro (Delete_Rows_User_Input) here: https://www.excelcampus.com/vba/delete-rows-cell-values/, but it would give an error when trying to run it pointing to the
Set lo = Sheet1.ListObjects(1) part of the code.
My end goal would be to click the macro and have it run an Import .txt file->loop Delete Rows Based on Cell Values->Save as .txt
I already have the Import .txt and save as .txt portions of the macro, I just need the last part. Thanks!
I am trying to generate a macro that would auto set the range I use ("$A$1:$O$1000"), and give the user the option to input one or more criteria to search and delete rows for.
I found this code at https://www.extendoffice.com/documents/excel/1747-excel-delete-row-if-zero.html:
Sub DeleteRows()'Updateby20140314
Dim rng As Range
Dim InputRng As Range
Dim DeleteRng As Range
Dim DeleteStr As String
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
DeleteStr = Application.InputBox("Delete Text", xTitleId, Type:=2)
For Each rng In InputRng
If rng.Value = DeleteStr Then
If DeleteRng Is Nothing Then
Set DeleteRng = rng
Else
Set DeleteRng = Application.Union(DeleteRng, rng)
End If
End If
Next
DeleteRng.EntireRow.Delete
End Sub
The difference I need from it is to preset the specified range and loop through the "Delete Text" part until the user is satisfied and presses "Cancel".)
I also found a similar macro (Delete_Rows_User_Input) here: https://www.excelcampus.com/vba/delete-rows-cell-values/, but it would give an error when trying to run it pointing to the
Set lo = Sheet1.ListObjects(1) part of the code.
My end goal would be to click the macro and have it run an Import .txt file->loop Delete Rows Based on Cell Values->Save as .txt
I already have the Import .txt and save as .txt portions of the macro, I just need the last part. Thanks!