I am struggling with extracting columns of many workbooks into one compilation file where I draw Charts of the compiled data... The struggle is that the file referring isn't working if less I have the workbooks open. Secondly, I have tried opening and copying values (by vba), but that is very slow... And some times neither that is working. Even when I have also used the full filepath and file name (with Dir() and everything...). For whatever reason, this code presented here works much faster, but only when the workbooks are open.
I guess it is partly that I am not familiar with most optimal way of extracting and compiling data from other workbooks... Will be greatfull for any tips! :) The dbug.prints are only for overview that everything runs as intended.
Sub hente_inn_celleverdier_original()
'Filenames are listed here: (165 + i, 8) (H166 and underneath) *Edit: wrote wrong celladdress here (G166), fixed now...*
'In the target files, EP23 and EQ23 tells the number of cells in that column/list extempting: "", blank, etc.
'(7, 263 + 2 * i [= 265]) is the upper left cell in the table which we are filling in the compilation file…
Application.ScreenUpdating = False
For i = 1 To 38 '=Number of series(number of files I am extracting these values from)
Debug.Print (Cells(165 + i, 8)) ' Prints filename (except part with filetype &".xlsx")
A = Workbooks(Cells(165 + i, 8) & ".xlsx").Sheets(1).Range("EP23")
Debug.Print A' Prints number from EP23.
Cells(7, 263 + 2 * i).Value2 = "='[" & Cells(165 + i, 8) & ".xlsx]CPTU'!EP28"
Cells(7, 263 + 2 * i).Select
Selection.AutoFill Destination:=Range(Cells(7, 263 + 2 * i), Cells(6 + A, 263 + 2 * i)),Type:=xlFillDefault
B = Workbooks(Cells(165 + i, 8) & ".xlsx").Sheets(1).Range("EQ23")
Debug.Print B' Prints number from EQ23.
Cells(7, 264 + 2 * i).Value2 = "='[" & Cells(165 + i, 8) & ".xlsx]CPTU'!EQ28"
Cells(7, 264 + 2 * i).Select
Selection.AutoFill Destination:=Range(Cells(7, 264 + 2 * i), Cells(6 + B, 264 + 2 * i)), Type:=xlFillDefault
Next 'i
Application.ScreenUpdating = True
End Sub