Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default search 2 spreadsheets and compare a value.


I know very little about programming macros but I really need a macro or
something to solve the following: How do I search Column A in
spreadsheet A and keep ONLY matching values that are found in
Spreadsheet B? In other words, go through each cell in spreadsheet B
and see if that value exists in spreadsheet A (let's say in column A).
If it does not exist, delete that cell and go on to the next one. If it
DOES exist in spreadsheet A, simply go on to the next cell and repeat
the process.


--
jeff5656
------------------------------------------------------------------------
jeff5656's Profile: http://www.excelforum.com/member.php...o&userid=25605
View this thread: http://www.excelforum.com/showthread...hreadid=471096

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default search 2 spreadsheets and compare a value.

the first part says to delete information in Spreadsheet A. The second part
says to delete information in Spreadsheet B. Also. you say column A in
Spreadsheet A, but infer all columns and rows in Spreadsheet B. Perhaps a
clear statement of what you want to do and what conditions to consider would
be in order.

--
Regards,
Tom Ogilvy


"jeff5656" wrote in
message ...

I know very little about programming macros but I really need a macro or
something to solve the following: How do I search Column A in
spreadsheet A and keep ONLY matching values that are found in
Spreadsheet B? In other words, go through each cell in spreadsheet B
and see if that value exists in spreadsheet A (let's say in column A).
If it does not exist, delete that cell and go on to the next one. If it
DOES exist in spreadsheet A, simply go on to the next cell and repeat
the process.


--
jeff5656
------------------------------------------------------------------------
jeff5656's Profile:

http://www.excelforum.com/member.php...o&userid=25605
View this thread: http://www.excelforum.com/showthread...hreadid=471096



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default search 2 spreadsheets and compare a value.

Hi,

I'm going to suppose that the changes are :
1) If it exists in SheetA and SheetB then let it be in SheetA
2) If it exists in SheetA or SheetB but not in both at the same time
delete it in SheetA

Let's suppose that your list has a maximum length of 10000 lines...

Then you first make a copy of both lists into a Variant, because an
Array can be searched much faster...

' So you define the Variants

Dim copyA as Variant, copyB as Variant

' Then you make the copy :

With Thisworkbook
CopyA = .Sheets("A").Range("a1:a10000")
CopyB = .Sheets("B").Range("a1:a10000")
End With

' Then you compare and delete the CopyA-value if both values are
different from each other

i=1
For i=1 to 10000
If CopyA(i,1) < CopyB(i,1) then
CopyA(i,1) = ""
endif
next

' Then you paste the CopyA-list back

With Thisworkbook.
..Sheets("A").Range("a1:a10000") = CopyA
End With

'... and it's ready to print...

Hope you can use it...

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default search 2 spreadsheets and compare a value.

so even though the two lists are not identical, you feel that any matches
will appear on exactly the same row in each list. Why not.

You might be better changing

CopyA(i,1) = ""

to

CopyA(i,1) = empty

--
Regards,
Tom Ogilvy

"xxpeter" wrote in message
oups.com...
Hi,

I'm going to suppose that the changes are :
1) If it exists in SheetA and SheetB then let it be in SheetA
2) If it exists in SheetA or SheetB but not in both at the same time
delete it in SheetA

Let's suppose that your list has a maximum length of 10000 lines...

Then you first make a copy of both lists into a Variant, because an
Array can be searched much faster...

' So you define the Variants

Dim copyA as Variant, copyB as Variant

' Then you make the copy :

With Thisworkbook
CopyA = .Sheets("A").Range("a1:a10000")
CopyB = .Sheets("B").Range("a1:a10000")
End With

' Then you compare and delete the CopyA-value if both values are
different from each other

i=1
For i=1 to 10000
If CopyA(i,1) < CopyB(i,1) then
CopyA(i,1) = ""
endif
next

' Then you paste the CopyA-list back

With Thisworkbook.
.Sheets("A").Range("a1:a10000") = CopyA
End With

'... and it's ready to print...

Hope you can use it...



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
compare 2 spreadsheets jono Excel Worksheet Functions 0 May 5th 08 12:58 PM
Compare spreadsheets [email protected] Excel Worksheet Functions 4 March 5th 08 02:07 PM
Compare Two Spreadsheets Ty Excel Discussion (Misc queries) 1 February 15th 06 05:09 PM
How do I search excel spreadsheets using multiple search criteria. Kasper Excel Worksheet Functions 4 December 15th 05 12:26 AM
How can I compare to spreadsheets Comparing similar data betwee two spread Excel Worksheet Functions 1 November 23rd 04 04:51 PM


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