chipsworld
Board Regular
- Joined
- May 23, 2019
- Messages
- 164
- Office Version
- 365
Help! I have been working on this for hours now, and having no luck...
I am trying to allow the user to select an Excel the source workbook, and perform a Two Dimensional lookup to pull that data into a target workbook.
There are 5 columns to import data to. The source sheet is "Exactly" the same as the target. I just need to import the data as there will be multiple source files that all match to different parts of the whole.
All lookup values are in Column A and all data to import is in Column c5 thru i234
Also...Once I get this part resolved, I need to figure out to import additional data for the same cells, and add the new numbers to the existing.
All Data points are numeric...
I am trying to allow the user to select an Excel the source workbook, and perform a Two Dimensional lookup to pull that data into a target workbook.
There are 5 columns to import data to. The source sheet is "Exactly" the same as the target. I just need to import the data as there will be multiple source files that all match to different parts of the whole.
All lookup values are in Column A and all data to import is in Column c5 thru i234
Also...Once I get this part resolved, I need to figure out to import additional data for the same cells, and add the new numbers to the existing.
All Data points are numeric...
VBA Code:
Private Sub cmdimport_Click()
Dim filter As String
Dim caption As String
Dim SourceF As String
Dim SourceW As Workbook
Dim TargetW As Workbook
Dim SourceS As Worksheet
Dim TargetS As Worksheet
On Error Resume Next
' make weak assumption that active workbook is the target
Set TargetW = Application.ThisWorkbook
' get the customer workbook
filter = "*.xl* (*.xls*),*.xls*"
caption = "Please Select file to import "
SourceF = Application.GetOpenFilename(filter, , caption)
Set SourceW = Application.Workbooks.Open(SourceF)
Set SourceS = SourceW.Worksheets("AAR")
Dim LastRow As Long
Dim r As Long
With SourceS
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For r = 5 To LastRow Step 1
'apply the two dimensional lookup formula using INDEX and MATCH
TargetW.Sheets("AAR").Cells(r, 3, 9).Value = Application.WorksheetFunction.Index(SourceS.Range("B5:I234"), _
Application.WorksheetFunction.Match(TargetW.Sheets("AAR").Cells(r, 3, 9), SourceS.Range("A5:I234"), 0), _
Application.WorksheetFunction.Match(TargetW.Sheets("AAR").Cells(r, 3, 9), TargetW.Sheets("AAR").Range("C2:I2"), 0))
Next r
End With
End Sub