Retrieving data from database

Pericic

Board Regular
Joined
Nov 11, 2005
Messages
204
Is there a way to retrieve data from a database based on date values??

I have a database on sheet 1 whose values change daily...(cumulative database)

I would like to preserve data on a separate sheet for each day...that is get the data from the database today, and keep it before it changes tomorrow??
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,453
Hello Pericic,
Sure, there are a number of ways to do that. The best of which would depend on possibly several factors, such as if you want to keep today's data on sheet2 (for example) and then overwrite it tomorrow with tomorrow's data or if you want each day's data to go (again in sheet2) below the previous day's data, or perhaps each day to a seperate sheet, or...(?)
What column(s) do you want to copy to the other sheet(s)?

If you can give us as many specific details as you can think of, as to what you want to do we can come up with a much more meaningful example of how to do it.
 

Pericic

Board Regular
Joined
Nov 11, 2005
Messages
204
Thanks for such a quick response...
I want to keep the data, I do not want to overwrite it...

I'd like each days data to go below previous days data..(doesn't really matter what column...

Once again thanks for your help halface
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,453
OK, (without more details) I'm having to make several assumptions here.
(1) This code will be run from the sheet you are copying from.
(2) You are only (ever) interested in copying the data specific to the current date at the time.
(3) Your dates are all in column A.
(4) You want to copy the entire row(s) for the day to the destination sheet.
(5) Your destination sheet is sheet2.

If all of these are acceptable then you should be able to use something like this:
Code:
Sub CopyDemo()
Dim SrchRng As Range, CpyRow As Range, c As Range
Set SrchRng = Range(Cells(1, 1), (Cells(Rows.Count, 1).End(xlUp)))

For Each c In SrchRng
    If c.Value = Date Then
        If CpyRow Is Nothing Then
            Set CpyRow = c
          Else: Set CpyRow = Union(c, CpyRow)
        End If
    End If
Next c

If Not CpyRow Is Nothing Then CpyRow.EntireRow.Copy _
    Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp)(2, 1)

End Sub
If this isn't doing what you want, or isn't close enough to be able to edit it to what you need you'll have to provide more details such as copy what, from where, to where, etc.

Hope it helps.
 

Pericic

Board Regular
Joined
Nov 11, 2005
Messages
204
OK, I see I need an example...

A1 is today

C7:G13 is my input data (input daily)

C1:G5 is the dynamic database....

I need to copy these database values for 12/27 to sheet 2 as they are now......
When I input values for 12/28 the database values will change.....but I dont want the copied values on sheet 2 for 12/27 to change....I'd like to repeat this process on a daily basis....

Thanks again for your time and expertise
Book1
ABCDEFG
112/27/200546789
246789
346789
446789
546789
6
726-Dec34444
827-Dec12345
928-Dec
1029-Dec
1130-Dec
1231-Dec
131-Jan
DB
 

Watch MrExcel Video

Forum statistics

Threads
1,118,167
Messages
5,570,640
Members
412,334
Latest member
ExcelForLifeDontHate
Top