M
murfyang
Hi there, new to excel forum & also slow learner in VBA. Am doing a
match date search & then copying that range of price with the date
range to another worksheet. used this code as suggested but unable to
work, it end with a "Start date not found" msg.
My date is in column B formatted as dd/mm/yyyy. Have tried adding the
cdate to the startdate & enddate & also changing the 0 to 1 in the
match function, but still the same.
Any one can help, thanks greatly
Code:
--------------------
Option Explicit
Sub FindDates()
Worksheets("Prices").Select
On Error Goto errorHandler
Dim startDate As String
Dim stopDate As String
Dim startRow As Integer
Dim stopRow As Integer
Dim rng1 As Range, rng2 As Range
Dim x As Variant, r As Range
startDate = InputBox("Enter the Start Date: (dd/mm/yyyy)")
If startDate = "" Then End
stopDate = InputBox("Enter the Stop Date: (dd/mm/yyyy)")
If stopDate = "" Then End
startDate = Format(startDate, "dd/mm/yyyy")
stopDate = Format(stopDate, "dd/mm/yyyy")
With Worksheets("Prices")
Set r = .Range(.Cells(1, 2), .Cells(65536, 2).End(xlUp))
End With
x = Application.Match(startDate, r, 0)
If IsNumeric(x) Then
startRow = x
Else
MsgBox "Start date not found"
End
End If
x = Application.Match(stopDate, r, 0)
If IsNumeric(x) Then
stopRow = x
Else
MsgBox "End date not found"
End
End If
match date search & then copying that range of price with the date
range to another worksheet. used this code as suggested but unable to
work, it end with a "Start date not found" msg.
My date is in column B formatted as dd/mm/yyyy. Have tried adding the
cdate to the startdate & enddate & also changing the 0 to 1 in the
match function, but still the same.
Any one can help, thanks greatly
Code:
--------------------
Option Explicit
Sub FindDates()
Worksheets("Prices").Select
On Error Goto errorHandler
Dim startDate As String
Dim stopDate As String
Dim startRow As Integer
Dim stopRow As Integer
Dim rng1 As Range, rng2 As Range
Dim x As Variant, r As Range
startDate = InputBox("Enter the Start Date: (dd/mm/yyyy)")
If startDate = "" Then End
stopDate = InputBox("Enter the Stop Date: (dd/mm/yyyy)")
If stopDate = "" Then End
startDate = Format(startDate, "dd/mm/yyyy")
stopDate = Format(stopDate, "dd/mm/yyyy")
With Worksheets("Prices")
Set r = .Range(.Cells(1, 2), .Cells(65536, 2).End(xlUp))
End With
x = Application.Match(startDate, r, 0)
If IsNumeric(x) Then
startRow = x
Else
MsgBox "Start date not found"
End
End If
x = Application.Match(stopDate, r, 0)
If IsNumeric(x) Then
stopRow = x
Else
MsgBox "End date not found"
End
End If