Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 159
Default Copy & Paste Only Those That Don't Exist

I think I've explained it all here, but I might have left something out:

In Wkbk1, Wksht1, look at every row that has something in it. If the contents of the range cells Ax:Bx of the row don’t appear in Wkbk2, Wksht1, Ax:Bx, copy the whole row and paste it into the next empty row of Wkbk2, Wksht1.

Any help/hints appreciated.

Thanks
Rob
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy & Paste Only Those That Don't Exist

Hi Rob,

Am Sat, 26 Oct 2013 05:22:08 -0700 (PDT) schrieb robzrob:

In Wkbk1, Wksht1, look at every row that has something in it. If the contents of the range cells Ax:Bx of the row don?t appear in Wkbk2, Wksht1, Ax:Bx, copy the whole row and paste it into the next empty row of Wkbk2, Wksht1.


if you use xl2007 or later you better copy all data and remove then
duplicates:

Sub Test2()

ThisWorkbook.Sheets("Sheet1").UsedRange.Copy _
Workbooks("wbk2.xlsx").Sheets("Sheet1") _
.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

With Workbooks("wbk2.xlsx").Sheets("Sheet1")
.UsedRange.RemoveDuplicates Columns:=Array(1, 2), _
Header:=xlNo
End With
End Sub

If the values in column A don't match you cannot test if the values im B
match. You can only look for column A:

Sub Test()
Dim rngC As Range
Dim c As Range
Dim LRow1 As Long, LRow2 As Long
Dim rng1 As Range, rng2 As Range

LRow1 = ThisWorkbook.Sheets("Sheet1") _
.Cells(Rows.Count, 1).End(xlUp).Row
LRow2 = Workbooks("wbk2.xlsx").Sheets("Sheet1") _
.Cells(Rows.Count, 1).End(xlUp).Row

Set rng1 = ThisWorkbook.Sheets("Sheet1").Range("A1:A" & LRow1)
Set rng2 = Workbooks("wbk2.xlsx").Sheets("Sheet1").Range("A1: A" & LRow2)

For Each rngC In rng1
Set c = rng2.Find(rngC, LookIn:=xlValues)
If c Is Nothing Then
ThisWorkbook.Sheets("Sheet1").Rows(rngC.Row).Copy _
Workbooks("wbk2.xlsx").Sheets("Sheet1") _
.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
End If
Next
End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 159
Default Copy & Paste Only Those That Don't Exist

On Saturday, 26 October 2013 15:27:56 UTC+1, Claus Busch wrote:
Hi Rob,



Am Sat, 26 Oct 2013 05:22:08 -0700 (PDT) schrieb robzrob:



In Wkbk1, Wksht1, look at every row that has something in it. If the contents of the range cells Ax:Bx of the row don?t appear in Wkbk2, Wksht1, Ax:Bx, copy the whole row and paste it into the next empty row of Wkbk2, Wksht1.




if you use xl2007 or later you better copy all data and remove then

duplicates:



Sub Test2()



ThisWorkbook.Sheets("Sheet1").UsedRange.Copy _

Workbooks("wbk2.xlsx").Sheets("Sheet1") _

.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)



With Workbooks("wbk2.xlsx").Sheets("Sheet1")

.UsedRange.RemoveDuplicates Columns:=Array(1, 2), _

Header:=xlNo

End With

End Sub



If the values in column A don't match you cannot test if the values im B

match. You can only look for column A:



Sub Test()

Dim rngC As Range

Dim c As Range

Dim LRow1 As Long, LRow2 As Long

Dim rng1 As Range, rng2 As Range



LRow1 = ThisWorkbook.Sheets("Sheet1") _

.Cells(Rows.Count, 1).End(xlUp).Row

LRow2 = Workbooks("wbk2.xlsx").Sheets("Sheet1") _

.Cells(Rows.Count, 1).End(xlUp).Row



Set rng1 = ThisWorkbook.Sheets("Sheet1").Range("A1:A" & LRow1)

Set rng2 = Workbooks("wbk2.xlsx").Sheets("Sheet1").Range("A1: A" & LRow2)



For Each rngC In rng1

Set c = rng2.Find(rngC, LookIn:=xlValues)

If c Is Nothing Then

ThisWorkbook.Sheets("Sheet1").Rows(rngC.Row).Copy _

Workbooks("wbk2.xlsx").Sheets("Sheet1") _

.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

End If

Next

End Sub





Regards

Claus B.

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2



Thanks, Claus. Haven't done any macros at all for a while. This will be an interesting re-start.
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
How to paste blanks only without overwrite exist cells in excel li Excel Discussion (Misc queries) 1 May 30th 07 12:43 PM
how to copy cells which gaps exist between? Jared Excel Discussion (Misc queries) 10 July 27th 06 03:21 PM
Copy Worksheet to a new Workbook creating if it doesn't exist and add more Worksheets if it does exist [email protected] Excel Programming 4 June 18th 06 06:08 PM
Command Line. How to tell to XL : If the xls file exist : Open it, if it does not exist : Create it. Tintin92 Excel Programming 3 March 11th 06 06:45 PM
search range, if exist, copy cell marcus76 Excel Programming 2 October 11th 04 06:01 PM


All times are GMT +1. The time now is 05:43 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"