ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting ranges by dates (https://www.excelbanter.com/excel-programming/368310-selecting-ranges-dates.html)

[email protected]

Selecting ranges by dates
 
I am trying to write the code that will allow me to input date ranges
and copy the information by the date that it was entered.


Tom Ogilvy

Selecting ranges by dates
 

Dim rng as Range, rng1 as Range
Dim ans as String, Target as Long
Dim res as Variant
with worksheets("Sheet1")
set rng = .range(.Cells(2,1),.Cells(2,1).End(xldown))
End with
ans = Inputbox("Enter your date:")
if cdate(ans) then
target = clng(cdate(ans))
res = Application.match(target,rng,0)
if not iserror(res) then
set rng1 = rng(res)
rng1.copy Destination:=worksheets("Sheet2").cells( _
rows.count,1).End(xlup)(2)
else
msgbox ans & " was not found"
end if
else
msgbox ans & " is not a valid date"
end if

--
Regards,
Tom Ogilvy

" wrote:

I am trying to write the code that will allow me to input date ranges
and copy the information by the date that it was entered.




All times are GMT +1. The time now is 10:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com