Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Comparing two ranges and extracting non duplicate data

Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2 ranges
with each other and then extract all the data that are in column D, but not
in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Comparing two ranges and extracting non duplicate data

in F1 put the formula
=if(countif(A:A,D1)=0,D1,"")

then drag fill down the column.

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2 ranges
with each other and then extract all the data that are in column D, but

not
in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Comparing two ranges and extracting non duplicate data

Thanks Tom,
can I use this in VBA code as well? I need this to be part of a bigger
procedure that I'm currently writing.
Thanks ;)

KJ

"Tom Ogilvy" wrote in message
...
in F1 put the formula
=if(countif(A:A,D1)=0,D1,"")

then drag fill down the column.

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2 ranges
with each other and then extract all the data that are in column D, but

not
in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Comparing two ranges and extracting non duplicate data

Hi again. I just read my original posting and can see myself that not
everything is quite clear in my explanation.
I'll try and put it in another way:
I have a whole load of data that I am manipulating with code and end up with
a sheet that looks like this:
A B C D E F
G H
1 35017 25000 09715 17000
2 35018 14100 35017 24990
3 35019 13000 35018 14120
4 35021 26200 35019 13000
5 35115 25150 35020 7520
6 35222 12600 35021 26200
7 35234 11550 35057 5200
...
The data in column A and D are transaction ID's. The data in B and E are the
values.
What I am trying to do is to cut the tansaction ID's in column D that are
not featured in column A and paste them in column G and H (G for the ID and
H for the value).
So in the above example tansaction ID 09715 with value 17000 would be pasted
to columns G and H and the rest of columns D and E would move up one row.

Hope this clears up my question a bit.
Again thanks for any help.

kj


"Knut Dahl" wrote in message
...
Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2 ranges
with each other and then extract all the data that are in column D, but
not in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Comparing two ranges and extracting non duplicate data

Range("F1").Formula = "=IF(COUNTIF(A:A,D1)=0,D1,"""")"

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Knut Dahl" wrote in message
...
Thanks Tom,
can I use this in VBA code as well? I need this to be part of a bigger
procedure that I'm currently writing.
Thanks ;)

KJ

"Tom Ogilvy" wrote in message
...
in F1 put the formula
=if(countif(A:A,D1)=0,D1,"")

then drag fill down the column.

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2

ranges
with each other and then extract all the data that are in column D, but

not
in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Comparing two ranges and extracting non duplicate data

Dim rng as Range, rw as Long
Dim rngA as Range, cell as Range
set rngA = Range(cells(1,"A"),Cells(rows.count,"A").End(xlup) )
set rng = Range(cells(1,"D"),cells(rows.count,"D").End(xlup) )
rw = 1
for each cell in rng
if application.Countif(rngA,cell.Value) = 0 then
cells(rw,"F").Value = cell.Value
rw = rw + 1
end if
Next

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Thanks Tom,
can I use this in VBA code as well? I need this to be part of a bigger
procedure that I'm currently writing.
Thanks ;)

KJ

"Tom Ogilvy" wrote in message
...
in F1 put the formula
=if(countif(A:A,D1)=0,D1,"")

then drag fill down the column.

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2

ranges
with each other and then extract all the data that are in column D, but

not
in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Comparing two ranges and extracting non duplicate data

Dim lastRow as Long, rw as Long
Dim rngA as Range
set rngA = Range(cells(1,"A"),Cells(rows.count,"A").End(xlup) )
lastRow = cells(rows.count,"D").End(xlup).row

rw = LastRow
for i = Lastrow to 1 step -1
if application.Countif(rngA,cells(i,"D").Value) = 0 then
cells(rw,"G").Value = cells(i,"D").Value
cells(rw,"H").Value = cells(i,"E").Value
cells(i,"D").Resize(1,2).Delete Shift:=xlShiftUp
rw = rw - 1
end if
Next
if isempty(cells(1,"G")) then
range(cells(1,"G"),cells(rw,"H")).Delete Shift:=xlShiftUp
End if

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Hi again. I just read my original posting and can see myself that not
everything is quite clear in my explanation.
I'll try and put it in another way:
I have a whole load of data that I am manipulating with code and end up

with
a sheet that looks like this:
A B C D E F
G H
1 35017 25000 09715 17000
2 35018 14100 35017 24990
3 35019 13000 35018 14120
4 35021 26200 35019 13000
5 35115 25150 35020 7520
6 35222 12600 35021 26200
7 35234 11550 35057 5200
...
The data in column A and D are transaction ID's. The data in B and E are

the
values.
What I am trying to do is to cut the tansaction ID's in column D that are
not featured in column A and paste them in column G and H (G for the ID

and
H for the value).
So in the above example tansaction ID 09715 with value 17000 would be

pasted
to columns G and H and the rest of columns D and E would move up one row.

Hope this clears up my question a bit.
Again thanks for any help.

kj


"Knut Dahl" wrote in message
...
Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2 ranges
with each other and then extract all the data that are in column D, but
not in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Comparing two ranges and extracting non duplicate data

Wow, works brilliantly.
You are a star. Thanks a million.

Regards

kj

"Tom Ogilvy" wrote in message
...
Dim rng as Range, rw as Long
Dim rngA as Range, cell as Range
set rngA = Range(cells(1,"A"),Cells(rows.count,"A").End(xlup) )
set rng = Range(cells(1,"D"),cells(rows.count,"D").End(xlup) )
rw = 1
for each cell in rng
if application.Countif(rngA,cell.Value) = 0 then
cells(rw,"F").Value = cell.Value
rw = rw + 1
end if
Next

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Thanks Tom,
can I use this in VBA code as well? I need this to be part of a bigger
procedure that I'm currently writing.
Thanks ;)

KJ

"Tom Ogilvy" wrote in message
...
in F1 put the formula
=if(countif(A:A,D1)=0,D1,"")

then drag fill down the column.

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2

ranges
with each other and then extract all the data that are in column D,
but
not
in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ










  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Comparing two ranges and extracting non duplicate data

Even better solution.
Thanks a million Tom.

kj


"Tom Ogilvy" wrote in message
...
Dim lastRow as Long, rw as Long
Dim rngA as Range
set rngA = Range(cells(1,"A"),Cells(rows.count,"A").End(xlup) )
lastRow = cells(rows.count,"D").End(xlup).row

rw = LastRow
for i = Lastrow to 1 step -1
if application.Countif(rngA,cells(i,"D").Value) = 0 then
cells(rw,"G").Value = cells(i,"D").Value
cells(rw,"H").Value = cells(i,"E").Value
cells(i,"D").Resize(1,2).Delete Shift:=xlShiftUp
rw = rw - 1
end if
Next
if isempty(cells(1,"G")) then
range(cells(1,"G"),cells(rw,"H")).Delete Shift:=xlShiftUp
End if

--
Regards,
Tom Ogilvy

"Knut Dahl" wrote in message
...
Hi again. I just read my original posting and can see myself that not
everything is quite clear in my explanation.
I'll try and put it in another way:
I have a whole load of data that I am manipulating with code and end up

with
a sheet that looks like this:
A B C D E
F
G H
1 35017 25000 09715 17000
2 35018 14100 35017 24990
3 35019 13000 35018 14120
4 35021 26200 35019 13000
5 35115 25150 35020 7520
6 35222 12600 35021 26200
7 35234 11550 35057 5200
...
The data in column A and D are transaction ID's. The data in B and E are

the
values.
What I am trying to do is to cut the tansaction ID's in column D that are
not featured in column A and paste them in column G and H (G for the ID

and
H for the value).
So in the above example tansaction ID 09715 with value 17000 would be

pasted
to columns G and H and the rest of columns D and E would move up one row.

Hope this clears up my question a bit.
Again thanks for any help.

kj


"Knut Dahl" wrote in message
...
Good morning everyone.
I am currently trying to compare 2 ranges with each other.
One range is in column A and the other in column D.
Column D contain more data than Column A. I want to compare the 2
ranges
with each other and then extract all the data that are in column D, but
not in column A and put them in a new column (F for example).
It might sound really easy, but I have tried various if...then and
do...while constructs, but it looks like I'm stuck logically.
Does anyone have a clever idea of how to solve this?
Any help is greatly apreciated.

Thanks guys

KJ







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
Comparing Data Across Cell Ranges Paul Excel Discussion (Misc queries) 2 May 4th 09 06:04 PM
Comparing two lists and extracting data from one to another Clement Excel Worksheet Functions 2 January 12th 06 06:38 PM
Extracting duplicate data from two lists nikf Excel Programming 1 April 26th 04 07:27 PM
Comparing 2 rows for duplicate data bkbri[_7_] Excel Programming 4 April 20th 04 08:39 AM
Comparing 2 Columns for duplicate data bkbri[_8_] Excel Programming 0 April 19th 04 09:34 PM


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