Привет всем, я получаю ошибку 1004, когда запускаю следующий код. в основном код сравнивает мой лист с листом в других книгах и копирует данные. я знаю, эта ошибка просто и я могу понять, но я нахожусь на срок .. пожалуйста, сообщитеОшибка времени выполнения 1004 заявленное определение или объектная ошибка
Sub test()
Dim lastCol, lastRow As Long, k, e As Long, a As Variant, b As Variant, cmpRng As Range
Dim mastCol As Long, mastRng As Range, n As Long
Dim Wbk As Workbook
Dim file As String
Dim SelectedFiles As Object
Dim filename As Variant
Dim indx As Long
Dim t As Integer
ChDrive "G:\" ' To set the drive where the files are located.
ChDir "g:\work" 'To set the folder where the files are located. This is done to save time locating the folder through pop up box always.
Application.ScreenUpdating = False
Sheets("Temp Calc").Select
'Clear existing sheet data ecept header.
Rows(1).Offset(1, 0).Resize(Rows.Count - 1).ClearContents
filename = Application.GetOpenFilename(FileFilter:="microsoft excel files (*.xlsx), *.xlsx", Title:="Get File", MultiSelect:=True)
Worksheets("Temp Calc").Select
lastCol = Worksheets("Temp Calc").Cells(1, Columns.Count).End(xlToLeft).Column
lastRow = Worksheets("Temp Calc").Cells(Rows.Count, 1).End(xlDown).Row
Set cmpRng = Range(Cells(1, 1), Cells(1, lastCol))
a = cmpRng
mastCol = Cells(1, Columns.Count).End(xlToLeft).Column
Set mastRng = Range(Cells(1, 1), Cells(1, mastCol))
b = mastRng
For t = 1 To UBound(filename)
Workbooks.Open (filename(t))
For k = 1 To lastCol
For n = 1 To mastCol
If UCase(a(1, k)) = UCase(b(1, n)) Then
Worksheets("Sheet1").Range(Cells(2, n), Cells(lastRow, n)).Copy
Windows("Dashboard_for_Roshan.xlsm").Activate
Worksheets("Temp Calc").Select
Cells(2,k).PasteSpecial Paste:=xlPasteAll,Operation:=xlNone,SkipBlanks:=False,Transpose:=False
****< I get an error for the above line >****
Exit For
End If
Next
Next
Next t
Application.ScreenUpdating = True
End Sub
благодарит за редактирования brettdj, я все еще должен понять правильную концепцию форматирования :) – mathew
hello mehow, Это неудобно, так как мой вопрос был сформулирован точно так же, как указано выше ... – mathew