Copying data from one workbook to another. Multiple columns and rows to copy and add to values already present...

chipsworld

Board Regular
Joined
May 23, 2019
Messages
161
Office Version
  1. 365
Hi all,
Not sure what I am doing here... I am trying to figure out how to copy data from one workbook (single sheet) to another workbook (1 sheet). The problem is that I have 5 columns of data on the source sheet, and multiple rows of data to copy. The column header is a date and the row data is a simple title.
I need to be able to select the source workbook, and copy the data from that workbook/sheet to the master workbook.

I have been researching how to use Match and Index, but can not figure out how to do it... Honestly, it is making me crazy.

I have the code to open the source workbook (below), but am completely lost on how to do the match and copy to the master workbook...

Any help would be greatly appreciated. I just need something generic that I can work with to get me running in the right direction...

Thanks!

VBA Code:
Dim wbThisWB    As Workbook
    Dim wbImportWB  As Workbook
    Dim strFullPath As String
    Dim i As String
    Dim m As Variant
    Dim result As String
    
    Set wbThisWB = ThisWorkbook
    
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .Title = "Please select a file to import:"
        .Filters.Add "Excel and CSV files", "*.csv; *.xls; *.xls*", 1
        .Show
        On Error Resume Next 'In case the user has clicked the <Cancel> button
            strFullPath = .SelectedItems(1)
            If Err.Number <> 0 Then
                Exit Sub 'Error has occurred so quit
            End If
        On Error GoTo 0
    End With
    
    Set wbImportWB = Workbooks.Open(strFullPath)
    Application.ScreenUpdating = False
    
   result = VLookup(wbImport.Sheets("data").cell(i, 1), wbThisWB.Sheets("S1 Daily Metrics"), Match(col_name, col_headers, 0), 0) [B]' was working with this, but honesltly can't figure out what to do with it, or how to use it correctly...[/B]
       
      
    Application.ScreenUpdating = True
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
OK...have been trying to figure this out and have come up with this basic function in the sheet...it sort of gets me what I want, but not?

=INDEX('[data source file.xlsx]Data'!$D$3:$H$47,MATCH($A5,'[data source file.xlsx]Data'!$A$4:$A$47,1),MATCH(B$2,'[data source file.xlsx]Data'!$D$2:$H$2,1))

No idea how to incorporate this into the VBA... I need to be able to run the above based upon the imported workbook. Worksheet name would always be the same, but the lookup in COlumn A will vary form sheet to sheet on the import, but not on consolidated... all labels will be there...
 
Upvote 0

Forum statistics

Threads
1,215,572
Messages
6,125,605
Members
449,238
Latest member
wcbyers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top