Hello everyone! could someone help me please I need to import the range data of all the selected files. The size range (4,1) and information is the same in all files and I need to import them to the main workbook where the range(4,1) information should be in the form (1,4) in each row of the main workbook . The data to import is:
I know that the line which is not working is A(i, j) = Awb.Sheets(1).Range(ImportRange).Cells(i, j) and maybe this Twb.Sheets("Data").Range("A&1:A4") = A(i, j)
I know that the line which is not working is A(i, j) = Awb.Sheets(1).Range(ImportRange).Cells(i, j) and maybe this Twb.Sheets("Data").Range("A&1:A4") = A(i, j)
VBA Code:
Sub RalphieReactor()
Dim Filenames() As Variant, i As Integer, A() As Variant, j As Integer, nw As Integer
Dim Twb As Workbook, Awb As Workbook, UserRange As Range, ImportRange As String
Set Twb = ThisWorkbook
Filenames = Application.GetOpenFilename(Title:="Open File(s)", MultiSelect:=True)
nw = UBound(Filenames)
For i = 1 To nw
Workbooks.Open Filenames(i)
Set Awb = ActiveWorkbook
Set UserRange = Application.InputBox(Prompt:="Range", Type:=8)
ImportRange = UserRange.Address
For j = 1 To 4
ReDim A(1, 4)
A(i, j) = Awb.Sheets(1).Range(ImportRange).Cells(i, j)
Twb.Activate
Twb.Sheets("Data").Range("A&1:A4") = A(i, j)
Awb.Close SaveChanges:=False
Next j
Next i
End Sub
Last edited by a moderator: