This way it's working for me:
Sub ImportCells()
Dim rngDest As Range
Dim oShell As Object
Dim strFolderPath As String
Dim strFileName As String
Set oShell = CreateObject("Shell.Application")
On Error Resume Next
strFolderPath = oShell.BrowseForFolder(0, "Select a Folder", 0).Self.Path & Application.PathSeparator
Set oShell = Nothing
On Error GoTo 0
If Len(strFolderPath) = 0 Then Exit Sub 'Pressed cancel
Set rngDest = ActiveWorkbook.ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Offset(0)
strFileName = Dir(strFolderPath & "*.xls")
Application.ScreenUpdating = False
Do While Len(strFileName) > 0
With Workbooks.Open(strFolderPath & strFileName)
If Evaluate("IsRef(CALCULAR!A1)") = True Then
rngDest.Value = strFileName
.Sheets("CALCULAR").Range("K1:AB5").Copy rngDest.Offset(0)
Set rngDest = rngDest.Offset(5)
Application.DisplayAlerts = False
'turns paste into paste special > values
Cells.Select
Selection.Copy
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues
End If
.Close False
End With
strFileName = Dir
Loop
Cells.Select
'Or Range("A1:S10000").Select
Selection.Copy
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
ActiveWorkbook.Save
Application.ScreenUpdating = True
Set rngDest = Nothing
End Sub
Thank you so, so much mikeTRON, you were the only who tried to help me!
Bookmarks