Marco to delete row base on date by input

Canon

New Member
Joined
Jul 31, 2018
Messages
2
I am trying to create a macro to delete the row if it doesnot equal a date inputted by the user.
When running the macro an input box should appear and theuser should be able to enter the date.
A B C D
Name Description Date Comment
1 Jeff Person 1 Jan-10-2018 123AAD
2 Bob Person2 Feb-12-2018 123AGV
3 Sara Person3 Jan-10-2018 125ABD
4 Joe Person 4 Feb-12-2018 1254ABX
The user would input Jan-10-2018, row 2 and 4 should bedeleted.
Thanks for your help in advance.

 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
A B C D

Name Description Date Comment
1 Jeff Person 1 Jan-10-2018 123AAD
2 Bob Person2 Feb-12-2018 123AGV
3 Sara Person3 Jan-10-2018 125ABD
4 Joe Person 4 Feb-12-2018 1254ABX

 
Upvote 0
Hello,

I assumed that your form is named: frm_userinput and input field fld_date.

This will get value of fld_date, then start looking for it in a column D in a loop. When it doesn't find anything it exits loop and ends macro. If a value is found it checks for a row number and then deletes whole row.

Code:
Sub del_data()

Dim x As String
Dim c As Range

x = frm_userinput.fld_date.Value
Do
   With Worksheets("Sheet1").Range("D:D")
        Set c = .Find(x)
        If Not c Is Nothing Then
            .Range("A" & c.Row).EntireRow.Delete
        Else
            Exit Do
        End If
   End With
Loop

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,897
Messages
6,122,151
Members
449,068
Latest member
shiz11713

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