ThrottleWorks
Excel Ninja
Hi,
I have 2 files.
File 1 has some text values, range is ("a2:a477").
I have file 2, I have to find each cell from File 1 in File 2.
If there are any results I have to copy that value & paste in File 1.
For example,
File 1, range A2 value = sachin
If I find Sachin in file 2, value in the File 1 Range B2 will be Sachin.
I am trying to do this by using following code.
I do not know, how to copy the value if the value is present.
If the value is not present, the macro will give bug, so I am using On Error Resume Next. (not given here, but is in the original code).
Can anyone help me in this please.
I have 2 files.
File 1 has some text values, range is ("a2:a477").
I have file 2, I have to find each cell from File 1 in File 2.
If there are any results I have to copy that value & paste in File 1.
For example,
File 1, range A2 value = sachin
If I find Sachin in file 2, value in the File 1 Range B2 will be Sachin.
I am trying to do this by using following code.
I do not know, how to copy the value if the value is present.
If the value is not present, the macro will give bug, so I am using On Error Resume Next. (not given here, but is in the original code).
Can anyone help me in this please.
Code:
Sub FindValue()
Dim MyRng As Range
Set MyRng = Range("a2:a477")
Dim MyWb As Workbook
Dim MyMacro As Workbook
Set MyWb = Workbooks("aaa.xlsx")
Set MyMacro = ActiveWorkbook
For Each rn In MyRng
rn.Copy
MyWb.Activate
Cells.Find(What:=rn.Value, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Next
End Sub