PC Review


Reply
Thread Tools Rate Thread

select data based on user input

 
 
Dave Ramage
Guest
Posts: n/a
 
      28th Jul 2003
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 : (E-Mail Removed)
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to input pictures automatically based on cell input? bsharp Microsoft Excel Worksheet Functions 9 30th May 2009 07:16 AM
run macro with input msg based on cell input Janelle S Microsoft Excel Misc 0 20th Jan 2008 06:23 AM
Trying to select a specific range based on the time value of user form input Jitranijam Microsoft Excel New Users 8 15th Nov 2006 01:52 AM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Microsoft Excel Programming 4 8th Dec 2003 04:22 PM
Select from one of three tables based on user input Alan DeHaven Microsoft Access Forms 2 8th Sep 2003 05:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:43 PM.