+ Reply to Thread
Results 1 to 4 of 4

Macro to copy specific data from one WB to specific cells in another WB based on specific

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2012
    Location
    connecticut
    MS-Off Ver
    Excel 2007
    Posts
    14

    Macro to copy specific data from one WB to specific cells in another WB based on specific

    Hello All, I'm looking for help in writing a Macro to copy specific data from one WB to specific cells in another WB based on specific criteria. I have 2 workbooks, one is Bill Of Materials, the other is a Vendor List. What I'm trying to accomplish is using the Vendor name I've entered in the BOM workbook to copy the "Phone" and "Contact" information from the Vendor List workbook to the appropriate Cells and Column in the BOM workbook.

    Any help is greatly appreciated. Thanks in advance

    br/dave r
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to copy specific data from one WB to specific cells in another WB based on speci

    Hi d_rose

    This Code will work on your Sample File...chances of it working in the Real World are slim.
    The Code assumes both Workbooks are in the Same Folder and runs from Sample BOM.
    Option Explicit
    
    Sub Match_Vendor()
        Dim wb As Workbook, wb1 As Workbook
        Dim ws As Worksheet, ws1 As Worksheet
        Dim rng As Range, cel As Range
        Dim MyPath As String, FindString As String
        Dim wasOpen As Boolean
        Dim LR As Long
    
        Set wb = ThisWorkbook
        Set ws = wb.Sheets("Sheet1")
        MyPath = wb.path & "\"
    
        On Error Resume Next
        Set wb1 = Workbooks("Sample Vendor List.xlsx")
        On Error GoTo 0
    
        If wb1 Is Nothing Then
            Set wb1 = Workbooks.Open(MyPath & "Sample Vendor List.xlsx")
        Else
            wasOpen = True
        End If
    
        Set ws1 = wb1.Sheets("Sheet1")
    
        With ws
            LR = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
            For Each cel In .Range("F16:F" & LR)
                If Not cel.Value = "" Then
                    FindString = Split(cel.Text, " ")(0)
                    With ws1.Columns(1)
                        Set rng = .Find(What:=FindString, _
                                        After:=.Cells(.Cells.Count), _
                                        LookIn:=xlValues, _
                                        LookAt:=xlPart, _
                                        SearchOrder:=xlByRows, _
                                        SearchDirection:=xlNext, _
                                        MatchCase:=False)
                        If Not rng Is Nothing Then
                            ws.Cells(cel.Row, "G").Value = .Cells(rng.Row, "C").Value
                            ws.Cells(cel.Row, "H").Value = .Cells(rng.Row, "D").Value
                        Else
                        End If
                    End With
                End If
            Next cel
        End With
    End Sub
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    08-16-2012
    Location
    connecticut
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Macro to copy specific data from one WB to specific cells in another WB based on speci

    John, I want to thank you for your reply. The only changes I had to make were the references to the File & Sheet names used in the actual documents, other than that it worked exactly as I wanted and your efforts are much appreciated.

    Thanks again,
    dave

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to copy specific data from one WB to specific cells in another WB based on speci

    You're welcome...glad I could help. Thanks for the Rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. HELP! Macro to Copy specific cells from one sheet to another based on specific criteria
    By atriscritti in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-11-2012, 11:05 AM
  2. Macro to extract data from multiple workbooks, specific sheet, specific cells
    By crissandraauree in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2012, 03:54 PM
  3. Macro to copy specific data to specific columns from a pivot table
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-09-2012, 07:24 PM
  4. macro needed to sum specific data in specific cells
    By nasser in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-24-2011, 08:11 AM
  5. Replies: 3
    Last Post: 03-28-2011, 10:53 AM

Tags for this Thread

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