• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Match Copy.find Paste from Wb1 to another using a close Wb2

Excelnoub

Member
Good day,
I am working on enhancing my code. I need to incorporate the following.

I have information in my Wb1 in Sheet1 with Column A:Z. I have data each day to replace in my Wb1. At the end of the month I need to send this info to a workbook (wb2) in the same worksheet (Sheet1) by clicking a Command Button and in the background opening Wb2 looking for the same matching info in my Column A from Wb1 and copy.find the same Value in Wb2 in Column A and Pasting the information from B to Z.

Wb1 will need to make a loop by finding matches in my Column A in my Wb2 if a match is made then copy the row from B to Z from Wb1 then Pasting that range in Wb2 on the same matching row.

Here is a code I am using but for individual selection:

Code:
Private Sub CommandButton3_Click()
  Application.ScreenUpdating = False
  Application.EnableEvents = False
 
  Set wsSrc = ThisWorkbook.Worksheets("Sheet1")
  LastRow = wsSrc.Range("A" & Rows.Count).End(xlUp).row
  Set rngSrc = wsSrc.Range("A2:AC" & LastRow)
  Set wbArchive = Workbooks.Open(Filename:="My workbook 2 location\Name.xlsm")
  Set wsSrc = wbArchive.Worksheets("Sheet1")
  Set rngDst = wsSrc.Range("A" & Rows.Count).End(xlUp).Offset(1)
 
rngSrc.Copy
  rngDst.PasteSpecial xlPasteValues
  rngSrc.ClearContents
 
 Application.CutCopyMode = False
  wbArchive.Close SaveChanges:=True
 
  Range("A5").Select
 
  Application.EnableEvents = True
  Application.ScreenUpdating = True
End Sub

I don’t just need to copy on next available row but have a match and loop from each row in my Wb1 to match.copy and paste the value in my Wb2.

Please help... I have the start but I cannot seem to get the second part done
 
I was looking at the code from Luke M in another thread and looking to addapt it to my needs...

Code:
Sub CopyDta()
Dim wb1 As Workbook, wb2 As Workbook
Dim ws As Worksheet
Dim filePath As String
Dim searchValue As Variant
Dim myRange As Range
Dim fCell As Range
 
filePath = "C:\My documents\My Book.xls"
Set wb1 = ActiveWorkbook
Set myRange = ActiveSheet.Range("D40:D64")
searchValue = ActiveSheet.Range("A8").Value
 
Application.ScreenUpdating = False
'Open wb2
Set wb2 = Workbooks.Open(filePath)
 
'Search and find
Set fCell = Nothing
For Each ws In wb2.Worksheets
    Set fCell = ws.Cells.Find(searchValue)
    'Stop when we find the value
  If Not fCell Is Nothing Then
        myRange.Copy
        fCell.Offset(1).PasteSpecial (xlPasteValues)
        Exit For
    End If
Next ws
 
wb2.Close True
wb1.Close True 'You sure you want to do this?
 
Application.ScreenUpdating = True
End Sub

But my Range in Wb1 is A to Z (B to Z as my Search would be column A)
And my range in Wb2 is in Column A
and I would need to have my worksheet in my wb2 selected
 
Last edited:
Back
Top