Results 1 to 4 of 4

Thread: VBA help on pulling data from an external workbook

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    I don't know if you're up to cleaning up your attachments, but if you do, this should work.
    The two attached files are "cleaned up", everything more consistent like names, capitalization, spacing, same amount of sheets as names etc.
    Workbook "test (6).xlsx" needs to be saved to the desktop.
    Sub Maybe()
    Dim wb1 As Workbook, wb2 As Workbook, sh1 As Worksheet
    Dim i As Long, j As Long
    Application.ScreenUpdating = False
    Set wb1 = ThisWorkbook
    Set sh1 = wb1.Sheets("Sheet1")
    
    
    On Error Resume Next
        Set wb2 = Workbooks(sh1.Range("A1").Value)
        If Err Then Set wb2 = Workbooks.Open(CreateObject("WScript.Shell").specialfolders("Desktop") & "\" & sh1.Range("A1").Value)
    On Error GoTo 0
    
    
        For i = 4 To sh1.Cells(Rows.Count, 1).End(xlUp).Row
            sh1.Cells(i, 1).Offset(, 1).Resize(, 2).Value = wb2.Sheets("Data entry").Columns(1).Find(sh1.Cells(i, 1), , , 1).Offset(, 10).Resize(, 2).Value
                For j = 3 To 7
                     sh1.Cells(i, 1).Offset(, j).Value = wb2.Sheets(sh1.Cells(i, 1).Value).Columns(4).Find(sh1.Cells(i, 1).Offset(3 - i, j), , , 1).Offset(, 4).Value
                Next j
        Next i
        wb2.Close False
    Application.ScreenUpdating = False
    End Sub
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •