PC Review


Reply
Thread Tools Rate Thread

Comparing Problems

 
 
Jim Berglund
Guest
Posts: n/a
 
      9th Oct 2007


Private Sub Compare()
Dim x, y As Integer
Dim r, s As Variant
I'm trying to compare the contents of two worksheets, highlighting the
diffferences.
I thought it would be simple, and created the following - which doesn't
work.

Application.ScreenUpdating = False

For y = 1 To 25
For x = 1 To 100
Worksheets("D390").Select
r = Cells(x, y).Text
Worksheets("D390New").Select
s = Cells(x, y).Text
If s <> r Then
Cells(x, y).Select
With Selection.Interior
.ColorIndex = 6
End With
End If
Next
Next

End Sub
Could someone please explain what I've misssed or done wrong? Thanks
Jim Berglund

 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      9th Oct 2007

The following untested revision to your sub should be closer to what you want.
The key is to qualify each range call out with the appropriate worksheet.
Also, a row index should be Long not an Integer.
And, you must specify each data type for a variable or you get a Variant.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)
(take a look at the XL Companion add-in)


Private Sub CompareR1()
'not tested
Dim x As Long, y As Long
Dim r As String, s As String
Dim wsOld As Worksheet
Dim wsNew As Worksheet

Application.ScreenUpdating = False
Set wsOld = Worksheets("D390")
Set wsNew = Worksheets("D390New")

For y = 1 To 25
For x = 1 To 100
r = wsOld.Cells(x, y).Text
s = wsNew.Cells(x, y).Text
If s <> r Then
wsOld.Cells(x, y).Interior.ColorIndex = 6
End If
Next
Next
Set wsOld = Nothing
Set wsNew = Nothing
Application.ScreenUpdating = True
End Sub
'----------


"Jim Berglund"
<(E-Mail Removed)>
wrote in message
Private Sub Compare()
Dim x, y As Integer
Dim r, s As Variant
I'm trying to compare the contents of two worksheets, highlighting the
diffferences.
I thought it would be simple, and created the following - which doesn't
work.

Application.ScreenUpdating = False

For y = 1 To 25
For x = 1 To 100
Worksheets("D390").Select
r = Cells(x, y).Text
Worksheets("D390New").Select
s = Cells(x, y).Text
If s <> r Then
Cells(x, y).Select
With Selection.Interior
.ColorIndex = 6
End With
End If
Next
Next
End Sub
Could someone please explain what I've misssed or done wrong? Thanks
Jim Berglund

 
Reply With Quote
 
dan dungan
Guest
Posts: n/a
 
      9th Oct 2007
Where did you put the code?
Which version of excel are you using?

On Oct 9, 10:00 am, "Jim Berglund" <jazz...@shaw.ca> wrote:
> Private Sub Compare()
> Dim x, y As Integer
> Dim r, s As Variant
> I'm trying to compare the contents of two worksheets, highlighting the
> diffferences.
> I thought it would be simple, and created the following - which doesn't
> work.
>
> Application.ScreenUpdating = False
>
> For y = 1 To 25
> For x = 1 To 100
> Worksheets("D390").Select
> r = Cells(x, y).Text
> Worksheets("D390New").Select
> s = Cells(x, y).Text
> If s <> r Then
> Cells(x, y).Select
> With Selection.Interior
> .ColorIndex = 6
> End With
> End If
> Next
> Next
>
> End Sub
> Could someone please explain what I've misssed or done wrong? Thanks
> Jim Berglund



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLOOKUP results in problems in comparing Chris J Denver Microsoft Excel Worksheet Functions 3 26th Jul 2010 10:43 AM
Problems Comparing Shared Files Joseph Carrier Windows Networking 0 8th Nov 2005 12:51 AM
Problems when comparing doubles =?Utf-8?B?TWF0dCBCaWxsb2Nr?= Microsoft C# .NET 4 15th Oct 2004 09:19 PM
Problems with comparing data =?Utf-8?B?SmVmZg==?= Microsoft Excel Worksheet Functions 4 15th Apr 2004 06:40 PM
Problems with comparing documents - Word 2000 Flowers Microsoft Word Document Management 1 15th Oct 2003 05:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:13 AM.