I´m new and starting to make baby steps in VBA. I want to make a macro that opens CSV files and that asks for a range to be selected from the first file (I need to select a column vector and that range will be the same along the macro), extracts the data from that column vector and paste it as a row vector (transposes the data) in the original active workbook. I have tried lots of things but I think I´m missing some knowledge. I think maybe I need to make an array inside an array cause A(i)
has more than one element, it is itself an array. This is what I wrote:
Option Explicit
Option Base 1
Sub x()
Dim FileNames() As Variant, nw As Integer
Dim i As Integer, A() As Variant
Dim tWB As Workbook, aWB As Workbook
Set tWB = ThisWorkbook
Dim UserRange As Range
FileNames = Application.GetOpenFilename("CSV Files (*.csv*),*.csv*", , , , True)
nw = UBound(FileNames)
Application.ScreenUpdating = False
ReDim A(nw) As Variant
Set UserRange = Application.InputBox("Select range", "Range Selection", , , , , , 8)
For i = 1 To nw
Workbooks.Open FileNames(i)
Set aWB = ActiveWorkbook
A(i) = aWB.Sheets(1).Range("UserRange")
tWB.Activate
tWB.Sheets(1).Range.Cells(i, 1) = WorksheetFunction.Transpose(A)
aWB.Close SaveChanges:=False
Next i
End Sub
Thank you, I really appreciate your help