PDA

View Full Version : Find in different workbook



hunna
11-21-2011, 09:16 AM
I am trying to find the data in workbook2 by using data from certain range in workbook1.


Sub find()


Windows("Workbook2.xls").Activate
cell.find(What:=Workbooks("Workbook1").Worksheets("sheet1").Range("AP33").Value, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.Select
Application.CutCopyMode = False
Selection.Copy
Windows("workbook1").Activate

Range("K12").Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

End Sub




My code is not working. any help would be appreciated.

Thanks,

Bob Phillips
11-21-2011, 09:26 AM
This seems to work, but aren't you just trying to paste the same value you are looking for, which is pointless



Sub find()

Windows("Book2").Activate
Cells.find(What:=Workbooks("Book1").Worksheets("sheet1").Range("AP33").Value, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Activate

Application.CutCopyMode = False
Selection.Copy
Windows("Book1").Activate

Range("K12").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

End Sub

hunna
11-21-2011, 05:59 PM
Hello xld (http://www.vbaexpress.com/forum/member.php?u=2139),

Thank you very much for your help

What I am trying to do is finding the same data on workbook2 using data on workbook1 as a reference.

When the code activates workbook2, it will find the data and make that range (containing data) as a active-cell.

So I want to copy the data in the active-cell including certain set of data below and paste that data set on workbook1.



Since I have no background knowledge about VBA so I just record the macro and try to edit it.


PS sorry for my english.

Bob Phillips
11-22-2011, 02:48 AM
Does the code I give do what you want? From your explanatioin, it seems we need to copy more cells, not just the found cell, but how do we know how many?

hunna
11-22-2011, 05:39 AM
Hello xld,

Actually that is just some part that I want to know for my code.
The code that I use in my excel file is

Sub Show_MGF_Listbox()

Windows("XcelL_references.xls").Activate

Cells.Find(What:=Workbooks("XcelL.xls").Worksheets("MSMSCAL").Range("AP33").Value, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Activate

ActiveCell.Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select

Application.CutCopyMode = False
Selection.Copy
Windows("XcelL.xls").Activate
Range("K12").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


End Sub