PeterTaylor
Board Regular
- Joined
- Aug 5, 2010
- Messages
- 158
Dear All,
I am using excel 2007 and vista 64 bit.
I have the follow macro that steps thru a list of excel files appends the first 14 columns of data to a master files then searchs thru the added file adding the data in named columns to the equilvaent columns in the master column ( the column names in each added file are translated to master file coumn names in the master file.
There ~2700 files to add to the master file; the macro works fine when I step thru using debug but when I run the macro not only about 10% of the data is appended.
It appears that the macro does not completely the executed each line before moving on to the next. Is there a way to stop this?
Regards
Peter
I am using excel 2007 and vista 64 bit.
I have the follow macro that steps thru a list of excel files appends the first 14 columns of data to a master files then searchs thru the added file adding the data in named columns to the equilvaent columns in the master column ( the column names in each added file are translated to master file coumn names in the master file.
Code:
Sub copy_to_master_collar()
Application.DisplayAlerts = False
'Application.ScreenUpdating = False
Workbooks.Open Filename:="K:\collars\1AAA_AL_COLLARS.xlsm"
Workbooks.Open Filename:="K:\Collar_import_log_file.xlsm"
Dim bCol As Integer, myTest As String, strName As String, myTotalRows As Integer, myTotalColumns As Integer, _
myColumn As Integer, MyRow As Integer, MyRange As Range, mylist As String, myFilename As String, _
aRow As Integer, TestBlank As Integer, zRow As Integer, _
ZCol As Integer, myWindowname As String, xRow As Integer, xCol As Integer, myTotalCollarRows As Integer
'**************************
aRow = 2
zRow = 1
ZCol = 1
xRow = 1
xCol = 1
Sheets("imports").Select
' Start loop
Do
'On Error GoTo 0
' Define values to mylist and myFilename for current pass of Do - Loop cycle
mylist = Cells(aRow, 1).Value
myFilename = Cells(aRow, 2).Value
myWindowname = Cells(aRow, 3).Value
' check length of current mylist value,for a zero length
If Len(mylist) = 0 Then
' in case of stray blanks in unsorted data, check next 10 rows
If TestBlank < 10 Then
TestBlank = TestBlank + 1
' kick back to loop start
GoTo NoError:
Else
MsgBox "End of File Encountered The Procedure will now exit"
'ActiveWorkbook.Save
'ActiveWorkbook.Close
Windows("1AAA_AL_COLLARS.xlsm").Activate
'ActiveWorkbook.Save
'ActiveWorkbook.Close
Application.DisplayAlerts = True
'Application.ScreenUpdating = True
Exit Do
End If
End If
' a valid entry needed to get here so reset testblank to 0
TestBlank = 0
' for a non zero length value of mylist, report current value to user and attempt to open file
'************************
Workbooks.Open mylist
myTotalRows = ActiveSheet.UsedRange.Rows.Count
myTotalColumns = ActiveSheet.UsedRange.Columns.Count
'Test if the last row has drill hole data
If Len(Cells(myTotalRows, 16)) = 0 Then
Rows(myTotalRows).Select
Selection.Delete Shift:=xlUp
myTotalRows = myTotalRows - 1
'Else
'GoTo Point A
End If
'Point A:
'Copy the fist 14 colunms of data to main file
Range(Cells(2, 1), Cells(myTotalRows, 14)).Select
Selection.Copy
Windows("1AAA_AL_COLLARS.xlsm").Activate
myTotalCollarRows = ActiveSheet.UsedRange.Rows.Count
myTotalCollarRows = myTotalCollarRows + 1
'Cells(1, 2).Select
'Selection.End(xlDown).Select
'MyRow = ActiveCell.Row + 1
Cells(myTotalCollarRows, 2).Select
ActiveSheet.Paste
' copy the rest of the data colunm by colunm to main file
Windows(myWindowname).Activate
bCol = 15
' set to run while row 1 not blank
While Len(Cells(1, bCol)) > 0
Cells(1, bCol).Select
myTest = Trim(UCase(ActiveCell.Value))
On Error GoTo NomatchSkip1
'strName = ""
strName = WorksheetFunction.VLookup(myTest, _
Workbooks("Collar_import_log_file.xlsm").Worksheets("Lookup").Range("A1:B1368"), 2, False)
Range(Cells(2, bCol), Cells(myTotalRows, bCol)).Select
Selection.Copy
Windows("1AAA_AL_COLLARS.xlsm").Activate
'Set MyRange = Worksheets("Sheet1").Names(strName).RefersToRange
Range(strName).Select
Selection.End(xlDown).Select
'MyRow = ActiveCell.Row + 1
myColumn = ActiveCell.Column
Cells(myTotalCollarRows, myColumn).Select
ActiveSheet.Paste
GoTo point1
'bCol = bCol + 1
'Windows("1.xlsx").Activate
NomatchSkip1:
Resume point1
point1:
bCol = bCol + 1
Windows(myWindowname).Activate
Wend
' on exit bCol set ready for the next file
bCol = 15
Windows(myWindowname).Activate
ActiveWorkbook.Close
Windows("Collar_import_log_file").Activate
aRow = aRow + 1
Sheets("Clean imports").Select
Cells(zRow, 1).Value = mylist
myTotalRows = myTotalRows - 1
Cells(zRow, 2).Value = myTotalRows
zRow = zRow + 1
Sheets("imports").Select
NoError:
Loop
End Sub
There ~2700 files to add to the master file; the macro works fine when I step thru using debug but when I run the macro not only about 10% of the data is appended.
It appears that the macro does not completely the executed each line before moving on to the next. Is there a way to stop this?
Regards
Peter