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



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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Comparing Problems


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"

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default Comparing Problems

Where did you put the code?
Which version of excel are you using?

On Oct 9, 10:00 am, "Jim Berglund" 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
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
aauugghhh...#div/o problems & various average formula problems acbel40 Excel Worksheet Functions 5 October 19th 09 05:00 PM
Comparing more than two Vern Excel Worksheet Functions 4 September 24th 08 04:03 PM
Problems comparing data from multiple blank cells monkeyhop Excel Worksheet Functions 4 May 2nd 06 05:48 AM
Problems merging an excel file due to code or file problems? Cindy M -WordMVP- Excel Programming 0 September 14th 04 02:58 PM
Comparing Kirk[_4_] Excel Programming 1 December 2nd 03 08:35 PM


All times are GMT +1. The time now is 12:34 PM.

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"