LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macro copy data into another workbook

I found this small macro which copies the data from my source worksheet
("Data4") Range("A1:C1000") to a different workbook ("C:\Destination.xls").
What it does is that it will look for the next empty row and then copy the
data into it. Now I would like to alter the macro so instead of always
copying into the next empty row (and eventually create duplicates) it should
check for the whole range if an entry from column A in the source range
already exists in column A of the detination workbook and in this case
overwrite column B and C of this row in the destination workbook. In case it
does not exist yet, it should write the data in the empty row as the macro
below does already. One more note: the data of the cells in column A of the
source worksheet is always unique, there are no duplicates already in the
source worksheet. Thanks for your help!

Sub Test()
Dim bk As Workbook
Dim bSave As Boolean
Dim lRow As Long

' test to see if Destination.xls is already open

On Error Resume Next
Set bk = Workbooks("Destination.xls")
On Error GoTo 0
If bk Is Nothing Then
bSave = True
Set bk = Workbooks.Open("C:\Destination.xls")
End If

'find first empty row in database
lRow = bk.Worksheets("Test").Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
ThisWorkbook.Sheets("Data4").Range("A1:C1000").Cop y _
Destination:=bk.Worksheets("Test").Cells(lRow, 1)

' if destination was originally closed, then save and close it

If bSave Then bk.Close Savechanges:=True

End Sub
 
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 most recent data from one workbook to another with a Macro Eli[_4_] Excel Discussion (Misc queries) 0 October 2nd 08 11:20 PM
Macro Help. Copy data from 1 workbook to another on next available Howeecow Excel Discussion (Misc queries) 0 June 6th 07 08:29 PM
Macro to copy data into another workbook yukon_phil Excel Discussion (Misc queries) 0 July 26th 06 05:29 PM
Macro to copy data from one workbook to another supamari0 Excel Programming 1 June 19th 06 09:09 PM
macro to copy range data from another workbook steven_thomas[_3_] Excel Programming 0 January 18th 06 07:01 PM


All times are GMT +1. The time now is 02:33 PM.

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

About Us

"It's about Microsoft Excel"