|  

» 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
Worksheets("Sheet2").Cells.ClearContents
Rows(aCell.Row & ":" & bCell.Row).Copy Worksheets("Sheet2").Range("A1")
End
ErrorHandler:
Beep
MsgBox "Not valid Date!"
End Sub



Rate This Tip
12 34 5
Rating: 2.23     Views: 23598
No comments have been submitted.
Click here to post comment
For Registered Users
Name
Comment Title
Comments