Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 113
Default Copy data from one worksheet to another

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default 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
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 113
Default Copy data from one worksheet to another

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").Ran ge("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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy from B worksheet to A worksheet with NO repeated data tikchye_oldLearner57 Excel Discussion (Misc queries) 1 September 29th 06 06:56 PM
copy data in a cell from worksheet A to worksheet B rajesh Excel Discussion (Misc queries) 1 February 21st 06 07:40 AM
Copy data into a NEW worksheet Krefty Excel Discussion (Misc queries) 1 December 22nd 04 01:53 PM
Copy Modified Worksheet 1 Data to Worksheet 2 clarkelrc Excel Programming 0 April 15th 04 01:36 PM
copy all worksheet data into a new worksheet eric Excel Programming 2 October 2nd 03 08:33 PM


All times are GMT +1. The time now is 07:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"