将多个工作簿复制到单个工作簿中#34;您无法在此处粘贴,因为复制区域为vba"

时间:2018-04-18 02:55:21

标签: excel vba excel-vba copy-paste

我尝试使用filedialog方法打开所有选定的文件,然后将所选路径中的所有内容复制到当前工作簿。第一个路径文件设法复制所有内容,当它到达第二个时,错误:

  

"你不能粘贴在这里因为复制区域,只选择粘贴区域中的一个单元格。"

以下是我的代码:

Sub Select_File_Click()
Dim lngCount As Long
    Dim cl As Range
    Dim c2 As Range
    Dim ItemType As String

    ThisWorkbook.Sheets("Sheet1").Range("A:D").ClearContents
    Set cl = ActiveSheet.Cells(1, 3)
    ' Open the file dialog
    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = True
        .Filters.Clear
        .Filters.Add "comma-separated values", "*.csv"
        .InitialFileName = "*" & ItemType & "*.*"
        .InitialView = msoFileDialogViewDetails
        .Show
        For lngCount = 1 To .SelectedItems.Count

            ' Add Hyperlinks
            cl.Worksheet.Hyperlinks.Add _
            Anchor:=cl, Address:=.SelectedItems(lngCount), _
                TextToDisplay:=.SelectedItems(lngCount)
            ' Add file name
            'cl.Offset(0, 1) = _
            '    Mid(.SelectedItems(lngCount), InStrRev(.SelectedItems(lngCount), "\") + 1)
            ' Add file as formula
            cl.Offset(0, 1).FormulaR1C1 = _
                 "=TRIM(RIGHT(SUBSTITUTE(RC[-1],""\"",REPT("" "",99)),99))"


            Set cl = cl.Offset(1, 0)
            Set c2 = cl.Offset(0, 1)
        Next lngCount
        Sheets(1).Cells(1, 1) = .SelectedItems.Count

End With
End Sub

Sub All_data_Click()
Dim Count As Integer
Dim iLast As Long

ThisWorkbook.Sheets("Copy").Range("A1:AZ5000").ClearContents
Count = ThisWorkbook.Sheets(1).Cells(1, 1)
iLast = 1

For i = 1 To Count
pth = ThisWorkbook.Sheets("Sheet1").Cells(i, 3).Value 'Select folder path
Set LookupWB = Workbooks.Open(Filename:=pth)
Set sourceColumn1 = ThisWorkbook.Sheets("Copy")
Set Source = ActiveWorkbook.Sheets(1)
Set sourceColumn1 = Source.Columns("A:AZ")
Set targetColumn1 = ThisWorkbook.Worksheets("Copy").Rows(iLast)
sourceColumn1.Copy Destination:=targetColumn1   <---Error Here: 
iLast = iLast + sourceColumn1.Range("A" & Rows.Count).End(xlUp).Row
Next i


End Sub

有什么想法可以解决这个问题吗?我已经迷路了。

1 个答案:

答案 0 :(得分:1)

如果我理解你想要做什么,我建议采用一种稍微不同的方法:

src/Vector.hs:36:42: error:
    • Could not deduce (Applicative (Vec c))
        arising from a use of ‘sequenceA’
      from the context: Num a
        bound by the instance declaration at src/Vector.hs:35:10-37
    • In the first argument of ‘vmult’, namely ‘(sequenceA x)’
      In the second argument of ‘($)’, namely ‘(vmult (sequenceA x) y)’
      In the expression: Matrix $ (vmult (sequenceA x) y)
   |
36 |   Matrix x . Matrix y = Matrix $ (vmult (sequenceA x) y)
   |                                          ^^^^^^^^^^^