Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compare Cells


Hello:

Iam trying to compare several columns on two sheets.

For example compare all the contents of column A,B,C,D on sheet1 with
the corresponding columns A,B,C,D on sheet2. Once it runs the
comparison, all cells which do not contain the same corresponding
values (ex sheet1.cell(a1) and sheet2.cell(a1)) will be colored yellow.
A Message box would also appear telling how many incorrect matches have
been found.

Please can someone help me
Thank you

Also could such a macro be used on more than two sheets simultaneously.


--
kwedde01
------------------------------------------------------------------------
kwedde01's Profile: http://www.excelforum.com/member.php...o&userid=24156
View this thread: http://www.excelforum.com/showthread...hreadid=386563

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default Compare Cells

Hi here ya go

Sub CompareSheets()
Dim Cell As Range

Sheet1.Range("A:D").Interior.ColorIndex = xlColorIndexNone
Sheet2.Range("A:D").Interior.ColorIndex = xlColorIndexNone
For Each Cell In Sheet1.Range("A:D").Cells
If Cell.Value < Sheet2.Range(Cell.Address).Value Then
Cell.Interior.ColorIndex = 6
Sheet2.Range(Cell.Address).Interior.ColorIndex = 6
End If
Next Cell
End Sub


Best wishes,

Bill Benson, CPA/MBA
President
XLCREATIONS.COM
http://www.xlcreations.com

With you in the fight against "Automation Apathy" ©



"kwedde01" wrote in
message ...

Hello:

Iam trying to compare several columns on two sheets.

For example compare all the contents of column A,B,C,D on sheet1 with
the corresponding columns A,B,C,D on sheet2. Once it runs the
comparison, all cells which do not contain the same corresponding
values (ex sheet1.cell(a1) and sheet2.cell(a1)) will be colored yellow.
A Message box would also appear telling how many incorrect matches have
been found.

Please can someone help me
Thank you

Also could such a macro be used on more than two sheets simultaneously.


--
kwedde01
------------------------------------------------------------------------
kwedde01's Profile:
http://www.excelforum.com/member.php...o&userid=24156
View this thread: http://www.excelforum.com/showthread...hreadid=386563



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default Compare Cells

With tally and message box...

Sub CompareSheets()
Dim Cell As Range, Dim i As Long

Sheet1.Range("A:D").Interior.ColorIndex = xlColorIndexNone
Sheet2.Range("A:D").Interior.ColorIndex = xlColorIndexNone
For Each Cell In Sheet1.Range("A:D").Cells
If Cell.Value < Sheet2.Range(Cell.Address).Value Then
Cell.Interior.ColorIndex = 6
i = i + 1
Sheet2.Range(Cell.Address).Interior.ColorIndex = 6
End If
Next Cell

If i 0 Then MsgBox "There " & IIf(i 1, "were ", "was ") & _
Format(i, "#,##0") & " mismatched " & IIf(i 1, "values.", "value.")

End Sub

"kwedde01" wrote in
message ...

Hello:

Iam trying to compare several columns on two sheets.

For example compare all the contents of column A,B,C,D on sheet1 with
the corresponding columns A,B,C,D on sheet2. Once it runs the
comparison, all cells which do not contain the same corresponding
values (ex sheet1.cell(a1) and sheet2.cell(a1)) will be colored yellow.
A Message box would also appear telling how many incorrect matches have
been found.

Please can someone help me
Thank you

Also could such a macro be used on more than two sheets simultaneously.


--
kwedde01
------------------------------------------------------------------------
kwedde01's Profile:
http://www.excelforum.com/member.php...o&userid=24156
View this thread: http://www.excelforum.com/showthread...hreadid=386563



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compare Cells


Hey thanks alot for the help, by any chance if i wanted it to search
every cell on the sheet1 and every cell on sheet2, without having to
specify a certain range, how would I do that?


--
kwedde01
------------------------------------------------------------------------
kwedde01's Profile: http://www.excelforum.com/member.php...o&userid=24156
View this thread: http://www.excelforum.com/showthread...hreadid=386563

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Compare Cells

For Each Cell In Sheet1.Range("A:D").Cells
change to this
For Each Cell In Sheet1.Range("A:IV").Cells

But you better be ready to take a long break - that's a lot of cells to
check

I would consider
For Each Cell In Sheet1.UsedRange

or build code to find the Last Cell and restrict your range to A1:LastCell

dim lr as long, lc as long

lr = Sheet1.Cells.SpecialCells(xlLastCell).Row
lc= Sheet1.Cells.SpecialCells(xlLastCell).Column

For each cell in range(cells(1,1),cells(lr,lc))
--
steveB

Remove "AYN" from email to respond
"kwedde01" wrote in
message ...

Hey thanks alot for the help, by any chance if i wanted it to search
every cell on the sheet1 and every cell on sheet2, without having to
specify a certain range, how would I do that?


--
kwedde01
------------------------------------------------------------------------
kwedde01's Profile:
http://www.excelforum.com/member.php...o&userid=24156
View this thread: http://www.excelforum.com/showthread...hreadid=386563



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 column cells and return the adjacent columns cells data of the cell trebor57 Excel Worksheet Functions 1 February 1st 11 02:54 PM
Compare 1 cell to column of cells returning adjacent cells info? Mr. Fine Excel Worksheet Functions 1 April 15th 10 07:36 PM
How do I compare cells and if FALSE compare to next cell in EXCEL Cindie Excel Worksheet Functions 0 March 24th 06 05:29 PM
Compare two cells from reference cells Mike K Excel Worksheet Functions 2 November 26th 05 02:07 PM
Compare 2 cells in 2 worksheets, rewrite one of the cells dbomb Excel Programming 1 September 28th 04 09:16 AM


All times are GMT +1. The time now is 06:47 AM.

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"