Copy data from one worksheet to another

G

Guest

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 Intege
Dim tempvar As Strin
Dim tempvar2 As Strin
Dim i As Intege
Dim xlapp1 As Workshee
Dim xlapp2 As Workshee

Set xlapp1 = Workbooks("blah.xls").Worksheets("texting"
Set xlapp2 = Workbooks("blah2.xls").Worksheets("texting2"

For i = 2 To 554
'Application.ScreenUpdating = Fals
'For i = 2 To 200
Set c = Nothin
xlapp1.Activat
xlapp1.Application.Goto reference:=Rows(i).Columns("A"
tempvar = xlapp1.Application.ActiveCell.FormulaR1C
With xlapp2.Range("a1:a2000"
Set c = .Find(what:=tempvar, MatchCase:=True
End Wit
If c Is Nothing The
Els
xlapp2.Activat
x = xlapp2.Application.ActiveCell.Ro
' xlapp2.Application.Goto reference:=Rows(x).Columns("C"
' tempvar2 = xlapp2.Application.Selectio
MsgBox tempvar
xlapp2.Rows(x).Columns("D").FormulaR1C1 = "Yes
xlapp1.Rows(i).Columns("D").FormulaR1C1 = tempvar

' tempvar2 = xlapp2.Rows(Application.ActiveCell.Row).Columns("C").FormulaR1C
' xlapp2.Rows(Application.ActiveCell.Row).Columns("D").FormulaR1C1 = "Yes
' xlapp1.Rows(i).Columns("D") = tempvar
End I
Nex
Application.ScreenUpdating = Tru

End Sub
 
N

Nathan

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").FormulaR1C1
' xlapp2.Rows
(Application.ActiveCell.Row).Columns("D").FormulaR1C1
= "Yes"
 
G

Guest

I've never used vlookup before, but from what I can tell by reading help, it can only pull data from different columns in the same row? The two workbooks have many different IDs. I have figured out how to do what I want to do, though, taking an entirely different approach

Public Sub blah(

Dim rngCell As Workshee
Dim FndRng As Rang

For i = 2 To

Set rngCell = Workbooks("testbook1.xls").Sheets("Sheet1"

Set FndRng = Workbooks("testbook2.xls").Sheets("Testsheet").Range("A:A").Find(rngCell.Rows(i).Columns("A").Value

If Not FndRng Is Nothing The
If FndRng.Offset(0, 3).Value = "Yes" The
MsgBox "This Cell's Value has already been pulled once!! (Possible Duplicate)", vbExclamatio
FndRng.Offset(0, 4).Value = rngCell.Rows(i).Columns("A").Valu
Els
FndRng.Offset(0, 3).Value = "Yes
rngCell.Rows(i).Columns("D").Value = FndRng.Offset(0, 2).Valu
End I
End I

Nex

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top