Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Data from another worksheet based on user input Alvyn Excel Worksheet Functions 14 August 6th 08 05:41 PM
Moving data in one excel column to another sheet based on user input [email protected] Excel Discussion (Misc queries) 1 May 10th 07 05:47 PM
Incrementing Data based on user input learningaccess Excel Discussion (Misc queries) 3 January 26th 07 03:28 PM
Trying to select a specific range based on the time value of user form input Jitranijam New Users to Excel 8 November 15th 06 12:52 AM
Finding a record based on user input Soundman Excel Discussion (Misc queries) 5 June 21st 05 03:06 AM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"