Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
select data based on user input
If the dates are sorted, then this will work:
Sub GetData() 'assuming sorted by dates ascending Dim strTemp As String Dim dtStart As Date, dtEnd As Date Dim lR1 As Long, lR2 As Long Dim wsW As Worksheet Do 'get start date strTemp = Application.InputBox("Enter start date:", Type:=2) If strTemp = "False" Then Exit Sub Loop While Not IsDate(strTemp) dtStart = CDate(strTemp) Do 'get end date strTemp = Application.InputBox("Enter end date:", Type:=2) If strTemp = "False" Then Exit Sub Loop While Not IsDate(strTemp) dtEnd = CDate(strTemp) 'find largest date <= dtStart lR1 = Application.Match(CLng(dtStart), Sheets ("Sheet1").Range("A:A"), 1) 'add one line if necessary If Sheets("Sheet1").Cells(lR1, 1).Value < dtStart Then lR1 = lR1 + 1 lR2 = Application.Match(CLng(dtEnd), Sheets ("Sheet1").Range("A:A"), 1) Set wsW = ActiveWorkbook.Worksheets.Add Sheets("Sheet1").Range("A" & lR1 & ":B" & lR2).Copy Destination:=wsW.Cells(1) End Sub Cheers, Dave. -----Original Message----- hi there i have 2 columns of data say column A as date and column B as output from 1990 to 2003 ....on " sheet 1 " i want to write a macro which asks the user to input start date and end date and then when i run the macro it shud display the dates and the corresponding output on a diff worksheet say "sheet 2" how can i do this ? do i neeed to use offset or index functions ? thanks 4 ur help. sam email : . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Extracting Data from another worksheet based on user input | Excel Worksheet Functions | |||
Moving data in one excel column to another sheet based on user input | Excel Discussion (Misc queries) | |||
Incrementing Data based on user input | Excel Discussion (Misc queries) | |||
Trying to select a specific range based on the time value of user form input | New Users to Excel | |||
Finding a record based on user input | Excel Discussion (Misc queries) |