Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Compare same Column in 2 Workbooks

I have 2 workbooks and want to compare Column A in both books. If there
is no match for an item in WB1 Column A to WB2 Column A, I want to
highlight or insert a cheater column in WB1 indicating "not in WB2".
Similarly, if something is found in WB2 and not in WB1, highlight in a
different color or "not in WB1". TIA

Greg

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compare same Column in 2 Workbooks


You don't need to write a macro to do this... you could do it with the
VLookup function or the index and Match...

i.e. insert column B of WB1 copy down for length of data in the column
=if(type(Vlookup(a1,[WB2.xls]Sheet1!$A:$A,1,False))=16,"Not in
WB2","")

repeat for wb2 as well should should give you want...

either that or a function like this...

Sub CompareColumns()
Dim wb1 as workbook
dim wb2 as workbook
dim ws1 as worksheet
dim ws2 as worksheet
dim rng1 as range
dim rng2 as range
dim c1 as range
dim c2 as range
dim bfound as boolean

set wb1 = Workbooks("WB1")
set wb2 = Workbooks("WB2")
set ws1 = wb1.activesheet
set ws2 = wb2.activesheet
set rng1 = ws1.range(cells(1,1),cells(ws1.usedrange.rows.coun t, 1))
Set rng2 = ws2.range(cells(1,1),cells(ws2.usedrange.rows.coun t, 1))

for each c1 in rng1
if c1 < "" then
bfound = false
for each c2 in rng2
if c1.value = c2.value then
bfound = true
end if
next
if not bfound then
range(c1.offset(0,1).address).Value = "Not in WB2"
end if
end if
next
for each c2 in rng2
if c2 < "" then
bfound = false
for each c1 in rng1
if c1.value = c2.value then
bfound = true
end if
next
if not bfound then
range(c2.offset(0,1).address).value = "Not in WB1"
end if
end if
next
end sub


--
kraljb
------------------------------------------------------------------------
kraljb's Profile: http://www.excelforum.com/member.php...fo&userid=9955
View this thread: http://www.excelforum.com/showthread...hreadid=400966

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Compare same Column in 2 Workbooks

Kraljb, thank for your formula, but when I try your sub, I get an error
on the line set range:

set rng1 = ws1.range(cells(1,1),cells(ws1*.usedrange.rows.cou nt, 1))
Set rng2 = ws2.range(cells(1,1),cells(ws2*.usedrange.rows.cou nt, 1))

Thanks

Greg

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 and Merge Workbooks PA New Users to Excel 2 November 6th 09 08:48 PM
Compare workbooks Andy Excel Discussion (Misc queries) 11 April 5th 09 11:46 PM
Compare workbooks Scafidel Excel Discussion (Misc queries) 2 May 28th 07 09:15 PM
compare different workbooks kjstec Excel Worksheet Functions 1 October 17th 06 06:34 PM
compare data from one column with another and compare result to yet another Matt Williamson[_3_] Excel Programming 1 September 25th 03 08:54 PM


All times are GMT +1. The time now is 11:16 AM.

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"