Find date and select all till last row

kamalm

New Member
Joined
Jul 30, 2018
Messages
33
Hi, I have sheet contains numerous data along with date in Column A. Of course the date will be different everyday depending on the date of the production. How can I create macro code to find the desired date and select from the first row of the desired date(untill Column X) to the last row of the sheet.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You didn't say what you want to do with the selection once its made, but this should get you to the point where the desired range is selected. Note the comment following the InputBox so you request the date to be found in the format appropriate to your regional settings
Code:
Sub Kamalm()
Dim Fnd As Range, D, lastRw As Long
D = InputBox("Enter Date to be found in column A in format mm/dd/yyyy") 'change date format to suit
If D = "" Then
    MsgBox "You clicked Cancel - exiting sub"
    Exit Sub
Else
    Set Fnd = Range("A:A").Find(D, , xlFormulas, xlWhole)
    If Not Fnd Is Nothing Then
        lastRw = ActiveSheet.Cells.Find("*", searchdirection:=xlPrevious, searchorder:=xlByRows).Row
        Fnd.Resize(lastRw - Fnd.Row + 1, 24).Select
        'do something with the selection
    Else
        MsgBox "The date you entered was not found in column A"
    End If
End If
End Sub
 
Upvote 0
thanks for responding Joe! Unfortunately it seems cannot find the date. But when I try entered other values, the code is working fine. Oh btw, I need to cut and paste on a new sheet after select the selection.
 
Upvote 0
thanks for responding Joe! Unfortunately it seems cannot find the date. But when I try entered other values, the code is working fine. Oh btw, I need to cut and paste on a new sheet after select the selection.
As I said in post #2 , it's essential that the date be entered in the exact format of the date you are trying to find.
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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