I am trying to copy Range(A14:N26) from every closed workbook in a folder on my desktop and paste them into the current worksheet (which is my master worksheet). The code does grab the right range of data but struggles with the pasting part. It is supposed to SpecialPaste the code as there are formulas in the cells and I want to only copy what is visible in the cells. (Note: The outcome of some of of the formulas are words, the outcome of others are numbers)
Option Explicit
Sub CopySheetFromFileOnDesktop()
Dim wkbDest As Workbook
Dim wksDest As Worksheet
Dim wkbSource As Workbook
Dim wksSource As Worksheet
Dim MyPath As String
Dim MyFile As String
Dim SheetIndex As Integer
Application.ScreenUpdating = False
Set wkbDest = ThisWorkbook
Set wksDest = wkbDest.Worksheets("Master Sheet")
SheetIndex = 1
MyPath = "C:\Users\.."
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "*.xlsm")
Do While Len(MyFile) > 0
Set wkbSource = Workbooks.Open(MyPath & MyFile)
Set wksSource = wkbSource.Worksheets("Sheet containing the info")
If WorksheetFunction.CountA(wkbSource.Sheets("Sheet containing the
info").Range("A14:L26")) <> 0 Then
'lRow = .Range("L" & Rows.Count).End(xlUp).Row 'UNSURE HOW TO LAST ROW
wkbSource.Sheets("Sheet containing the info").Range("A14:L26").Copy
wkbDest.Range("A:L" & Rows.Count).End(xlUp)(2).PasteSpecial _
Paste:=xlPasteValues 'PASTESPECIAL SEEMS TO BE THE PROBLEM
wkbSource.Close savechanges:=False
Application.CutCopyMode = False
Else
End If
Loop
Application.ScreenUpdating = True
MsgBox "Completed...", vbInformation
End Sub
when running the macro it shows this bug: Runtime Error 438: Object does not support Properties or Method. And the debugger highlights the line where I define where to paste the copied range