» 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:
- Microsoft Office XP Step-By-Step (With CD-ROM)
- Real Estate Finance and Investments (Real Estate Finance and Investments, 11th Ed)
- Microsoft Excel Version 2002 Step by Step
- H&R Block's Just Plain Smart(tm) Tax Planning Advisor: A year-round approach to lowering your taxes this year, next year and beyond
- Millionaire Real Estate Mentor : The Secrets of Financial Freedom through Real Estate Investing
- The Intelligent Investor: The Classic Bestseller on Value Investing
No comments have been submitted.

