Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88809

Selecting data from multiple files and sorting them into another workbook

$
0
0

I'm trying to copy a selected piece of data from multiple files (vector) and putting them into another workbook as transposed data.

Here is what I have (In multiple workbooks with different values each) enter image description here

And Here is what I want to arrange that data into (In one workbook) enter image description here

Here is my code

Option Explicit
        Option Base 1

        Sub ArrangeData()

        Dim A() As String, nw As Integer
        Dim i As Integer, FileNames As Variant
        Dim tWB As Workbook, aWB As Workbook
        Dim rng As range

    Set tWB = ThisWorkbook

    MsgBox ("Enter files that you wish to import data from.")

    FileNames = Application.GetOpenFilename(FileFilter:="Excel Filter (*.csv), *.csv", Title:="Open File(s)", MultiSelect:=True)

    MsgBox ("The first file will now open, Select the rage you wish to import. This range will be imported from each of the files you selected.")

    nw = UBound(FileNames)
    ReDim A(nw) As String
    For i = 1 To nw
        If i = 1 Then
            Workbooks.Open FileNames(i)
            Set aWB = ActiveWorkbook
            Set rng = Application.InputBox(Title:="Select Range", Prompt:="Range", Type:=8)
            aWB.Close SaveChanges:=False
        End If
        tWB.Worksheets("Data").range("A"& i) = WorksheetFunction.Transpose(rng)
    Next i
    End Sub

This does not seem to take each different vectors from other worksheets, but only one vector from the first worksheet. What can I do to make this work?


Viewing all articles
Browse latest Browse all 88809

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>