» Search and copy date values using VBA
CATEGORY - Date & Time in VBA
VERSION - All Microsoft Excel Versions
Question: Dates are to be copied in an area with a start and end value inquired by a input boxAnswer: 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
Book Store:
Recommended Books:
- The Intelligent Investor: The Definitive Book On Value Investing, Revised Edition
- Business Plans Kit for Dummies (With CD-ROM)
- Now, Discover Your Strengths
- The Essential 55: An Award-Winning Educator's Rules for Discovering the Successful Student in Every Child
- Dictionary of Finance and Investment Terms
- Special Edition Using Microsoft Excel 2002
No comments have been submitted.

