+ Reply to Thread
Results 1 to 7 of 7

Copying data from external workbook into current workbook based on cell value

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Copying data from external workbook into current workbook based on cell value

    Public Sub copyto()
    
        Dim cell As Range, wb As Workbook, twb As Workbook, dwb As Workbook
        Dim nname As String, lwf As String, dwf As String
    
        Application.Screenupdating = false
    
        Set twb = ThisWorkbook
        Set dwb = Workbooks.Open(Range("B2"))
    
        twb.Activate
    
        For Each cell In Range("A5", Cells(Rows.Count, 1).End(xlUp))
            If cell.Value <> "" Then
                lwf = cell.Value
    
                dwb.Activate
    
                With twb
                    cell.Offset(0, 1) = Cells.Find(lwf, after:=Cells(1, 1), lookat:=xlWhole, Searchdirection:=xlNext, Searchorder:=xlByRows).Offset(0, 4)
                    cell.Offset(0, 2) = Cells.Find(lwf, after:=Cells(1, 1), lookat:=xlWhole, Searchdirection:=xlNext, Searchorder:=xlByRows).Offset(0, 8)
    
                End With
    
            End If
    
        Next cell
    
        twb.Activate
        dwb.Close savechanges = False
        Application.screenupdating = true
    
    End Sub
    Please let me know if this does the job.
    If you think that my answer was helpful, please click on the "Add to this user's Reputation" button.

  2. #2
    Forum Contributor
    Join Date
    01-23-2010
    Location
    Suffolk, England
    MS-Off Ver
    Office 365
    Posts
    271

    Re: Copying data from external workbook into current workbook based on cell value

    Hi,

    Thanks for the code. I forgot to tell you that there are more rows of data in the "Financial Data" workbook than in the "Variance" workbook and I just want to copy across when there's a match with those fields stated in the Variance workbook.

    Is this a simple modification to the code in your reply?

    Best wishes,

    Louise

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1