Copy and Paste link between workbooks
You do not have to use copy & paste.
First worksheet name = source
Second worksheet name = destination
See if this will work.
Sub FindMatches()
Dim sd As Worksheet
Dim dd As Worksheet
Dim cell As Range
Dim x As Long
Dim LastRowS As Long
Dim LastRowD As Long
Set sd = Worksheets("source")
Set dd = Worksheets("destination")
sd.Activate
LastRowS = Cells(Cells.Rows.Count, "L").End(xlUp).Row
Set rngS = Range("L2:L" & LastRowS)
dd.Activate
LastRowD = Cells(Cells.Rows.Count, "B").End(xlUp).Row
For x = 2 To LastRowD
For Each cell In rngS
If dd.Cells(x, 2).Value = cell.Value Then
dd.Cells(x, 14).Formula = cell.Offset(0, -4).Value
dd.Cells(x, 15).Formula = cell.Offset(0, -2).Value
dd.Cells(x, 16).Formula = cell.Offset(0, -1).Value
End If
Next
Next x
End Sub
HTH
--
Data Hog
"PhilosophersSage" wrote:
Ok figured out what I did wrong... had file names wrong in varable so the
code now works. Please help with searching wkbk1 data column L using data in
wkbk2 column B as search peramater and return row number to RowVar1.
Windows(wkbk1).Activate
Range("H" & RowVar1).Select
Selection.Copy
Windows(wkbk2).Activate
Range("N" & RowVar2).Select
ActiveSheet.Paste Link:=True
Windows(wkbk1).Activate
Range("J" & RowVar1).Select
Application.CutCopyMode = False
Selection.Copy
Windows(wkbk2).Activate
Range("O" & RowVar2).Select
ActiveSheet.Paste Link:=True
Windows(wkbk1).Activate
Range("K" & RowVar1).Select
Application.CutCopyMode = False
Selection.Copy
Windows(wkbk2).Activate
Range("P" & RowVar2).Select
ActiveSheet.Paste Link:=True
"PhilosophersSage" wrote:
Still cannot figure out search and compare function but was able to figure
out copy link function. Just cannnot get the varables to work. I tried adding
a varable to the code but then it would not work. any pointers on search and
varable help is much appreciate, thank you!
Windows("source data.xlsm").Activate
Range("H266").Select 'would like to change to Range("H"&RowVar1)
Selection.Copy
Windows("Destination data.xlsx").Activate
Range("N45").Select 'would like to change to Range("N"&RowVar2)
ActiveSheet.Paste Link:=True
Windows("source data.xlsm").Activate
Range("J266").Select 'would like to change to Range("H"&RowVar1)
Application.CutCopyMode = False
Selection.Copy
Windows("Destination data.xlsx").Activate
Range("O45").Select' would like to change to Range("N"&RowVar2)
ActiveSheet.Paste Link:=True
Windows("source data.xlsm").Activate
Range("K266").Select 'would like to change to Range("H"&RowVar1)
Application.CutCopyMode = False
Selection.Copy
Windows("Destination data.xlsx").Activate
Range("P45").Select 'would like to change to Range("N"&RowVar2)
ActiveSheet.Paste Link:=True
"PhilosophersSage" wrote:
I have several workbooks, source data (SD) and destination data (DD) which
are portions of SD, I would like to make a macro that would search for
matching values between SD column L & DD column B and if there is a match
copy a link from SD column H, J & K to DD column N, O & P this way I can
reduce entry points for data.
The big problem I have is the search between workbooks, also I cannot get
the paste function to give a link between workbooks. Any help or pointers
anyone can give me I would really appreciate it! Thank you!
|