LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Consolidate external data -- proofread #2

Hi All -

I'm like to use the following code to 'consolidate' data from approx
30 external data files into one Master file. The code works perfectly
until it gets to the 16th file, where I get the infamous Run-time
Error 1004. The line where I get the error can be found between the
****** (towards the end of the code).

If I take out the 16th file and re-run the macro, it again stops at
the 16th file (used to be the 17th) -- so, I'm 99% sure that it's not
data file related, but something in my code.

All data files are named identically, with only the 1st three digits
being different. I'm using XL2003 on XP ... any help is greatly
appreciated ...
[I'm sure there's some 'junk' code (ie unused variables) in this --
I've been tinkering for days with it .... ]

Sub FetchStoreData()
Dim MyPath, getstore As String
Dim FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount, x As Long
Dim Fnum, i As Long
Dim mybook As Workbook
Dim basebook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim ws, sh As Worksheet

MyPath = "\\retus100-nt0009\common_b\na-cash\US\DailySales\2007
Daily Sales\"

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xls")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

' On Error GoTo CleanUp

Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False

Set basebook = ThisWorkbook
'clear all cells on all sheets
For Each ws In basebook.Worksheets
ws.UsedRange.ClearContents
Next

'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath < ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum), 0)

' Isolates the store number from the workbook name
getstore = Left(mybook.Name, 3)

Set sourceRange = mybook.Sheets("Store
SRA").Range("F:AF").EntireColumn

Set destrange = basebook.Sheets(getstore).Range("A1")

With sourceRange
Set destrange =
basebook.Sheets(getstore).Range("A1").Resize(.Rows .Count, .Columns.Count)
End With
'****** destrange.Value = sourceRange.Value
'******
mybook.Close savechanges:=False
Next
End If

Call ConsData 'consolidates data from store tabs to USA tab

CleanUp:
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

 
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
External Data Warning Message - I have No External Data in wrkbk Cass_makeitfun[_2_] Excel Discussion (Misc queries) 0 May 12th 10 09:02 PM
Getting External Data based on criteria insde of the external data BigMacExcel Excel Discussion (Misc queries) 0 August 31st 09 06:41 PM
Prompt for Korean proofread Mats Samson Excel Discussion (Misc queries) 0 November 15th 07 08:01 PM
consolidate data kim Excel Worksheet Functions 1 October 29th 07 11:36 PM
Proofread my code Ray Excel Programming 2 April 27th 07 02:00 PM


All times are GMT +1. The time now is 02:16 PM.

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

About Us

"It's about Microsoft Excel"