Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Compare Macro

Status
Not open for further replies.

tdpman

Technical User
Apr 29, 2002
44
US
Hi guys, I was wondering if one or more of you might be able to help me. I need a macro that will compare column C in 2 seperate workbooks (workbook A & B) and change the font color of any values in workbook A that are not in workbook B. Basically I have a report that is run daily listing several orders. Orders are added to this report daily and I need to have the NEW orders highlighted. Hope that makes sense. Any help you can give would be most appreciated.

Thanks again!
 
Try this - both workbooks must be open and you'll need to change the sheet names I imagine:

Sub FindNewOrders()
dim nSht as worksheet, oSht as worksheet, lRow as long
dim fWhat as string
set nSht = workbooks("A").sheets("Sheet1")
set oSht = workbooks("B").sheets("Sheet1")
lRow = nSht.range("C" & rows.count).end(xlup).row
for each c in nsht.range("C2:C" & lRow)
fWhat = c.text
with oSht.columns("C")
set fCell = .find(fWhat,lookin:=xlvalues,lookat:=xlwhole)
end with
if not fCell is nothing then
c.interior.colorindex = 3
else
end if
next
end sub

Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
I'll try that and see how it works. One question though, is there anyway to write it to where I wouldn't have to change the names of the workbook? I'm going to be using this everyday on workbooks that change names everday. Example: they change by date from "Report042303.xls" to "Report042403.xls". Any ideas?
 
Well, as long as it is always "Report" & Todays Date
compared to "Report" & Yesterdays Date then summat like:

tDate = format(now(),"dd/mm/yy")
if weekday(now())<>2 then
lDate = format(val(now())-1,&quot;dd/mm/yy&quot;)
else
lDate = format(val(now())-3,&quot;dd/mm/yy&quot;)

set nSht = workbooks(&quot;Report&quot; & tDate).sheets(&quot;Sheet1&quot;)
set oSht = workbooks(&quot;Report&quot; & lDate).sheets(&quot;Sheet1&quot;)


Rgds
Geoff
&quot;Some cause happiness wherever they go; others whenever they go.&quot;
-Oscar Wilde
 
Couple of ways (Posted previously by Gord Dibben in msnews):-

Myrna Larson and Bill Manville have written an add-in named Compare.xla that
is very hady for this type of problem. Can be downloaded in *.ZIP form from
Chip Pearson's site.


An alternative is Rob Bruce's CompareSheets.xla. Basically the same as above
except the differences are flagged rather than displayed on a new worksheet.

Can be downloaded as cmprshts.zip from Rob's site.


Regards
Ken................
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top