Results 1 to 8 of 8

Merging two worksheets together.

Threaded View

  1. #6
    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: Merging two worksheets together.

    Hi StrugInPP

    Place the two attached files in the same folder. Run the code from the button in Worksheet1. Let me know of issues.
    Option Explicit
    
    Sub Update_Book()
        Dim wb1 As Workbook
        Dim wb2 As Workbook
        Dim ws1 As Worksheet
        Dim ws2 As Worksheet
        Dim Rng1 As Range
        Dim Rng2 As Range
        Dim cel As Range
        Dim LR As Long
        Dim LC As Long
        Dim myPath As String
        Dim wasOpen As Boolean
    
    
        myPath = ThisWorkbook.Path & "\"
        Set wb1 = ThisWorkbook
        Set ws1 = wb1.Sheets("Sheet1")
        On Error Resume Next
        Set wb2 = Workbooks.Open(myPath & "worksheet 2.xlsx")
        Set ws2 = wb2.Sheets("Sheet1")
        On Error GoTo 0
    
        Application.ScreenUpdating = False
    
        If wb2 Is Nothing Then
            Set wb2 = Workbooks.Open(Workbooks.Open(myPath & "worksheet 2.xlsx"))
        Else
            wasOpen = True
        End If
    
        With ws2
            LC = .Cells.Find(What:="*", After:=[A1], _
                    SearchOrder:=xlByColumns, _
                    SearchDirection:=xlPrevious).Column + 1
        End With
    
        With ws1
            LR = .Range("C" & .Rows.Count).End(xlUp).Row
            Set Rng1 = .Range("C2:C" & LR)
            For Each cel In Rng1
                With ws2.Columns("A:A")
                    Set Rng2 = .Find(What:=cel, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
                    If Not Rng2 Is Nothing Then
                        ws2.Cells(Rng2.Row, LC).Value = ws1.Cells(cel.Row, 11).Value
                    End If
                End With
            Next cel
        End With
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

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