I am currently doing a report in which I will get the reports based on the link/path and file name I indicated in a specific cell and data should be transferred in the specific sheet I also indicated. This is needed as the path is always changing depending on where the user saved the files.
1st thing is, I have the "List" tab where I have inputted the file name and full path of each files and in what location should it be pasted. For example, File A should be pasted to "MasterData" sheet. File B, should be in the next tab, File C should be in the other tab.
Then, when I use the vba, it will get my files. File has been copied to "MasterData" sheet but the 2nd and 3rd file were copied under the data of File A which is my problem.
The 2nd file and 3rd files also are in text format but I want the Text Wizard to pop up first so the user can choose if the data should be delimited or Fixed width before copying it to the assigned sheets.
I cannot attach my file here :(
This is my current VBA code:
Public strFileName As String
Public currentWB As Workbook
Public dataWB As Workbook
Public strCopyRange As String
Sub GetData()
    Dim strWhereToCopy As String, strStartCellColName As String
    Dim strListSheet As String
    strListSheet = "List"
    On Error GoTo ErrH
    Sheets(strListSheet).Select
    Range("B2").Select
    'this is the main loop, we will open the files one by one and copy their data into the masterdata sheet
    Set currentWB = ActiveWorkbook
    Do While ActiveCell.Value <> ""
        strFileName = ActiveCell.Offset(0, 1) & ActiveCell.Value
        strCopyRange = ActiveCell.Offset(0, 2) & ":" & ActiveCell.Offset(0, 3)
        strWhereToCopy = ActiveCell.Offset(0, 4).Value
        strStartCellColName = Mid(ActiveCell.Offset(0, 5), 2, 1)
        Application.Workbooks.Open strFileName, UpdateLinks:=False, ReadOnly:=False
        Set dataWB = ActiveWorkbook
        Range(strCopyRange).Select
        Selection.Copy
        currentWB.Activate
        Sheets("MasterData").Select
        lastRow = LastRowInOneColumn(strStartCellColName)
        Cells(lastRow + 1, 1).Select
        Selection.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
        Application.CutCopyMode = False
        dataWB.Close False
        Sheets("List").Select
        ActiveCell.Offset(1, 0).Select
    Loop
    Exit Sub
ErrH:
    MsgBox "It seems some file was missing. The data copy operation is not complete."
    Exit Sub
End Sub
Public Function LastRowInOneColumn(col)
    'Find the last used row in a Column: column A in this example
    'http://www.rondebruin.nl/last.htm
    Dim lastRow As Long
    With ActiveSheet
    lastRow = .Cells(.Rows.Count, col).End(xlUp).Row
    End With
    LastRowInOneColumn = lastRow
End Function


 
     
     
    