multiple data source

  • Thread starter Thread starter mandela
  • Start date Start date
M

mandela

hello out there
i hope someone can help me with this problem.
i have 365 excel files each representing one day of sales and expenditure. they are all
identical template.
is there an easy way for me to import all the data from those files into one page that gives me
the sums?
any help is greatly appreciated.
mande
 
Hi

you could have a look at data / consolidation but i'm not sure how effective
this would be with 365 files ...
alternatively, if you're willing to use a VBA solution, you could put all of
your files in one folder .. use code to open them one at a time and then
copy & edit / paste special - ADD the other files on top of the first to end
up with just the final figures.

if you're interested in the second approach and only want to see the total
combined figures please reply back with the used ranges within the workbooks
(sheet names & ranges).

Cheers
JulieD
 
thanks julieD
what i need to do is to obtain 52 weekly reports from the 365 files on one sheet.
ideally it would have been nice to have 365 worksheets on the one file so i could create all the
desired reports.
your guidance is much welcome and appreciated

filenames are in this format eg : 1oct03(wed).xls ---> 1oct04(mon).xls
data contained in each file on : sheet1
cells range is A1 to L20
 
Hi mandela

okay i can give you some code that will combine each week's worth of
information onto a separate sheet in the workbook. Therefore, you'll end up
with 52 sheets in the combined workbook.

to do this
1) close all open workbooks but leave excel open - open a new workbook
2) choose tools / options / general - change sheets in a new workbook to
52 - close the open workbook
3) open a new workbook - it will have 52 sheets .. save it calling it
combined.xls
4) choose tools / options / general - change sheets in a new workbook back
to 3
5) right mouse click on sheet1's tab and choose view code
6) in the VBE editor widow choose insert / module from the menu
7) in the white piece of paper on the right copy & paste in the following:
'---
Sub namesheets()
Sheets(1).Activate
For i = 1 To 52
Sheets(i).Name = "Week" & i
Next
End Sub
'----
this will rename the sheet tabs for you - click inside the code and press
the F5 key, this will run the code
8)press Alt & F11 to get back to the workbook
9) go to sheet1 (now called week1) and put in the text ... the following
code will only add up the numbers, so you need to copy in any text you want
on each page and remove all numbers.
10) once sheet1 is correct, click on the week1 tab, hold down the shift key
and click on week52's tab, - let the shift key go, now select the active
area of week1 (the bit you typed in in step 9) and choose edit / fill across
worksheets ... now every sheet should look the same ... click on a few to
check
11) use alt & F11 to go back into the code... copy and paste the following
under the end sub of the previous lot of code
Sub findfile()
Dim fname As String
Dim fname2 As String
Dim pname As String
Dim dval
Dim i As Long
fname = "*.xls" 'filename
pname = "c:\temp\excel" 'folder to use
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = pname
.SearchSubFolders = False
.Filename = fname 'check to see if any files match the fname
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(i)
fname = ActiveWorkbook.Name
If Len(fname) = 15 Then
fname2 = "0" & fname
Else
fname2 = fname
End If
dval = "" & Left(fname2, 2) & "/" & Mid(fname2, 3, 3) & "/"
& Mid(fname2, 6, 2) & ""
dval = CDate(dval)
Select Case dval
Case Is <= (37895 + 6)
sname = "Week1"
Case Is <= (37895 + 13)
sname = "Week2"
Case Is <= (37895 + 20)
sname = "Week3"
Case Is <= (37895 + 27)
sname = "Week4"
Case Is <= (37895 + 34)
sname = "Week5"
Case Is <= (37895 + 41)
sname = "Week6"
Case Is <= (37895 + 48)
sname = "Week7"
Case Is <= (37895 + 56)
sname = "Week8"
Case Is <= (37895 + 63)
sname = "Week9"
Case Is <= (37895 + 70)
sname = "Week10"
Case Is <= (37895 + 77)
sname = "Week11"
Case Is <= (37895 + 84)
sname = "Week12"
'need to follow the same pattern for all 52 weeks
End Select
Range("A1:L20").Select
Selection.Copy
Windows("combined.xls").Activate
Sheets(sname).Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd,
SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Workbooks(fname).Close
Next
End If
End With
Application.ScreenUpdating = True
End Sub

'---
this is set up to do up to week 12 .. there's probably a neater way to do it
but i can't see it, so you'll need to add more lines in basically adding 7
to the number after the + and incrementing the week number until you get to
52

then once you've done that change
pname = "c:\temp\excel" 'folder to use
to the folder with these 365 files in (make sure there are no other files in
there)
and then click on the code and press F5

it might take awhile to run but what it should do, is open each file in
turn, check the date, and copy the information from sheet1 to the
appropriate week.

(note, you might want to test it on only a month's worth of files to start
with - so only have these in the folder when you run it)

Let me know how you go with this.

Cheers
JulieD
 
Hi

All in all you have 365*19=6935 or 365*20=7300 rows (depends on, have you
header row in every workbook or not). So there was no need to have 365
separate workbooks. For next year design a new yearly workbook with a
single input table (Date, a formula which calculates weeknumber from date,
and rest of your data). Autofilter feature is a great help when inserting
new data (set autofilter to display only rows with no data entered p.e.),
and FreezePanes feature keeps column headers always visible. And it's
relatively easy to have in Date column a formula, which displays all dates
from 1st January to current day - when tis is the case, then for input you
simply set autofilter to proper date. Additionally design into same workbook
some report sheets, like DailyReport, WeeklyReport, MonthlyReport,
YearlyReport, where you can select day, week or month, and wanted data in
raw or consolidated form (sums, counts etc.) are displayed.

When with report sheets the workbook remains too slow (because formulas on
report sheets), then you can create those reports as separate workbook(s),
which is/are getting data through links or through ODBC queries. You need a
bit more skills to design it/them, and working with several workbooks can be
uncomfortable, but sometimes you can gain much in perfomance this way.
 
hi JuliD
did all that i got the following error :

Run-time error '9'
subscript out of range

than debugged and the following was highlighted in yellow :

Sheets(sname).Select


any suggestions?
m
 
thanks.. will try that.. the data i got was from the previous person here so i have to do the
tidying up first...
 
Hi Mandela

check that the names of your sheets in the workbook aren't Week 1 but Week1
etc as per step 7

Cheers
JulieD
 
JulieD
i have checked
the names in the lines and in the worksheet are identical.
any ideas?
m
 
Hi Mandela

this is really hard to do via these type of posts ...:)

okay ... you're getting a "subscript out of range error on the following
lines"
Windows("combined.xls").Activate
Sheets(sname).Select 'highlighted in yellow
Range("A1").Select
change
Windows("combined.xls").Activate
to
workbooks("combined.xls").activate

and see if that makes a difference. If not, try placing the following line
of code in and seeing what "sname" evaluates to

workbooks("combined.xls").activate msgbox sname
Sheets(sname).Select 'highlighted in yellow
Range("A1").Select

if this doesn't give you a hint as to what's wrong, can you send me just the
"combined.xls" file to julied_ng at hcts dot net dot au and i'll see if i
can spot what is wrong with the code.

Cheers
JulieD
 
Back
Top