Search and copy date values using VBA

Question: Dates are to be copied in an area with a start and end value inquired by a input box

Answer: Insert the following code in the appropriate modules.

Place the code below into the standard module

Sub Marking()
Dim aCell As Range, bCell As Range
Dim Start
Dim Off
    On Error GoTo ErrorHandler
    Start = CDate(InputBox("Start:"))
    Set aCell = Columns(1).Find(DateValue(Start), LookIn:=xlFormulas)
    If aCell Is Nothing Then GoTo ErrorHandler
    Off = CDate(InputBox("End:"))
    Set bCell = Columns(1).Find(DateValue(Off), LookIn:=xlFormulas)
    If bCell Is Nothing Then GoTo ErrorHandler
    Rows(aCell.Row & ":" & bCell.Row).Copy Worksheets("Sheet2").Range("A1")
    MsgBox "Not valid Date!"
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *

3 − two =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>