2nd Input for Row Deletion Requirements not Applying Properly

Neild137

New Member
Joined
Mar 23, 2017
Messages
48
I had a code to prompt for two different inputs to search another sheet and the delete the entire row if two conditions where met (entry ID $ and date). I adjusted this to re-select the data worksheet, because it was originally also deleting the actual row of the worksheet that this button was located in.
I think the Date Input is no longer applying properly now. Anybody have any ideas?
Code:
<code>Sub DeleteRowNow()

On Error Resume Next

Dim userinput As String, DateInput As String
userinput = InputBox("Enter a value to search for.", "Column A Search")
DateInput = InputBox("Enter a date to search for.", "Column AN Search")
Dim findrange As Range
Dim firstaddress As String
Set findrange = ThisWorkbook.Sheets("Location File Data").Columns("A").Find(what:=userinput, lookat:=xlWhole, LookIn:=xlValues)
If findrange Is Nothing Then
MsgBox "No matching search results"
Exit Sub
Else
Sheets("Location File Data").Select
findrange.EntireRow.Select
Selection.EntireRow.Delete
Sheets("Compare").Select
End If

End Sub</code>
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
The only time Dateimput is in your code is where it is declared and where it is assigned a value. It is never used as a condition.


Code:
Sub DeleteRowNow()

On Error Resume Next

Dim userinput As String, [COLOR=#ff0000]DateInput As String[/COLOR]
userinput = InputBox("Enter a value to search for.", "Column A Search")
[COLOR=#ff0000]DateInput = InputBox("Enter a date to search for.", "Column AN Search")[/COLOR]
Dim findrange As Range
Dim firstaddress As String
Set findrange = ThisWorkbook.Sheets("Location File Data").Columns("A").Find(what:=userinput, lookat:=xlWhole, LookIn:=xlValues)
If findrange Is Nothing Then
MsgBox "No matching search results"
Exit Sub
Else
Sheets("Location File Data").Select
findrange.EntireRow.Select
Selection.EntireRow.Delete
Sheets("Compare").Select
End If

End Sub
 
Upvote 0
Code:
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim userinput As String, DateInput As String
userinput = InputBox("Enter a value to search for.", "Column A Search")
DateInput = InputBox("Enter a date to search for.", "Column AN Search")
Dim findrange As Range
Dim firstaddress As String
Set findrange = ThisWorkbook.Sheets("Location File Data").Columns("A").Find(what:=userinput, lookat:=xlWhole, LookIn:=xlValues)
If findrange Is Nothing Then
MsgBox "No matching search results"
Else
firstaddress = findrange.Address
Do
    If DateValue(DateInput) = Sheets("Location File Data").Cells(findrange.Row, "AN").Value Then
    Sheets("Location File Data").Select
    findrange.EntireRow.Select
    Selection.EntireRow.Delete
    Sheets("Compare").Select
        ThisWorkbook.Sheets("Location File Data").Range("A" & lastrowsheet2, "AN" & lastrowsheet2).Value = ThisWorkbook.Sheets("Sheet1").Range("A" & findrange.Row, "AN" & findrange.Row).Value
    End If
    Set findrange = ThisWorkbook.Sheets("Location File Data").Columns("A").FindNext(findrange)
    ' Loop until the Find has wrapped back around, or value not found any more
Loop While Not findrange Is Nothing And findrange.Address <> firstaddress
End If
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Are you getting an error or is it just not giving you the desired results?
 
Upvote 0
I am getting a catastrophic error on the following line:

Set findrange = ThisWorkbook.Sheets("Restated Data").Columns("A").Find(what:=userinput, lookat:=xlWhole, LookIn:=xlValues)
 
Upvote 0
I do not get an error on that line

I do get an error on this line Run-time Error '424': Object Required. Since you have deleted the row the findrange has been cleared. Also your code does not assign a value to lastrowsheet2
Code:
ThisWorkbook.Sheets("Location File Data").Range("A" & lastrowsheet2, "AN" & lastrowsheet2).Value = ThisWorkbook.Sheets("Sheet1").Range("A" & findrange.Row, "AN" & findrange.Row).Value
 
Upvote 0
Also you are setting the calculation to manual but not changing it back to automatic. I assume you want to change it to automatic.
 
Upvote 0
This worked for me
Code:
Sub DeleteRowNow()
Dim userinput As String, DateInput As String
userinput = InputBox("Enter a value to search for.", "Column A Search")
DateInput = InputBox("Enter a date to search for.", "Column AN Search")
Dim lr As Long
lr = Worksheets("Location File Data").Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 2 Step -1
    If UCase(Worksheets("Location File Data").Cells(i, 1)) = UCase(userinput) And Worksheets("Location File Data").Cells(i, 40) = DateValue(DateInput) Then
        Rows(i).EntireRow.Delete
    End If
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top