Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to paste blanks only without overwrite exist cells in excel | Excel Discussion (Misc queries) | |||
how to copy cells which gaps exist between? | Excel Discussion (Misc queries) | |||
Copy Worksheet to a new Workbook creating if it doesn't exist and add more Worksheets if it does exist | Excel Programming | |||
Command Line. How to tell to XL : If the xls file exist : Open it, if it does not exist : Create it. | Excel Programming | |||
search range, if exist, copy cell | Excel Programming |