Copy data from one worksheet to another
I would just use the VLookup function.
-----Original Message-----
I'm trying to copy data from one worksheet to another.
In the first sheet, there is an ID. I want to find that
ID in the second worksheet, and if that ID is found, copy
a data into the first sheet. Here is the code I have so
far, though it doesn't work. Any help would be greatly
appreciated =)
Public Sub DateCopy()
Dim x As Integer
Dim tempvar As String
Dim tempvar2 As String
Dim i As Integer
Dim xlapp1 As Worksheet
Dim xlapp2 As Worksheet
Set xlapp1 = Workbooks("blah.xls").Worksheets("texting")
Set xlapp2 = Workbooks("blah2.xls").Worksheets("texting2")
For i = 2 To 5547
'Application.ScreenUpdating = False
'For i = 2 To 2000
Set c = Nothing
xlapp1.Activate
xlapp1.Application.Goto reference:=Rows(i).Columns
("A")
tempvar = xlapp1.Application.ActiveCell.FormulaR1C1
With xlapp2.Range("a1:a2000")
Set c = .Find(what:=tempvar, MatchCase:=True)
End With
If c Is Nothing Then
Else
xlapp2.Activate
x = xlapp2.Application.ActiveCell.Row
' xlapp2.Application.Goto reference:=Rows
(x).Columns("C")
' tempvar2 = xlapp2.Application.Selection
MsgBox tempvar2
xlapp2.Rows(x).Columns("D").FormulaR1C1
= "Yes"
xlapp1.Rows(i).Columns("D").FormulaR1C1 =
tempvar2
' tempvar2 = xlapp2.Rows
(Application.ActiveCell.Row).Columns("C").FormulaR 1C1
' xlapp2.Rows
(Application.ActiveCell.Row).Columns("D").FormulaR 1C1
= "Yes"
' xlapp1.Rows(i).Columns("D") = tempvar2
End If
Next
Application.ScreenUpdating = True
End Sub
.
|