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

Hi
I am comparing two ranges of exactly the same size and prompting the
result as either a complete match or a mismatch even if one value
differs between the ranges. I tried:

Sub comp()
Dim FirstRange As Range, SecondRange As Range

Set FirstRange = Application.InputBox("Set first series: ", Type:=8)
Set SecondRange = Application.InputBox("Set Second series: ", Type:=8)

If Evaluate("SUM((EXACT(FirstRange,SecondRange)=FALSE )*1)") = 0 Then
MsgBox "Ranges are exact"
Else
MsgBox "Ranges differ"
End If
End Sub

This does not work and gives an error on "If Evaluate..." line. Could
someone help please.

I am also wondering if it can accomodate when one or both the values
are #NA type of errors.

Thanks
Utkarsh

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Comparing two ranges

Try this code:

Sub comp()

Dim FirstRange As Range
Dim SecondRange As Range
Dim arr1
Dim arr2
Dim i As Long
Dim c As Long

Set FirstRange = Application.InputBox("Set first series: ", Type:=8)
Set SecondRange = Application.InputBox("Set Second series: ", Type:=8)

If FirstRange.Columns.Count < SecondRange.Columns.Count Or _
FirstRange.Rows.Count < SecondRange.Rows.Count Then
MsgBox "The 2 ranges are not of the same size and shape!"
Exit Sub
End If

arr1 = FirstRange
arr2 = SecondRange

If FirstRange.Columns.Count = 1 And _
FirstRange.Rows.Count = 1 Then
If arr1 = arr2 Then
MsgBox "Ranges are exact"
Else
MsgBox "Ranges differ"
End If
Exit Sub
End If

For i = 1 To UBound(arr1)
For c = 1 To UBound(arr1, 2)
If Not arr1(i, c) = arr2(i, c) Then
MsgBox "Ranges differ"
Exit Sub
End If
Next
Next

MsgBox "Ranges are exact"

End Sub


RBS


"Utkarsh" wrote in message
ups.com...
Hi
I am comparing two ranges of exactly the same size and prompting the
result as either a complete match or a mismatch even if one value
differs between the ranges. I tried:

Sub comp()
Dim FirstRange As Range, SecondRange As Range

Set FirstRange = Application.InputBox("Set first series: ", Type:=8)
Set SecondRange = Application.InputBox("Set Second series: ", Type:=8)

If Evaluate("SUM((EXACT(FirstRange,SecondRange)=FALSE )*1)") = 0 Then
MsgBox "Ranges are exact"
Else
MsgBox "Ranges differ"
End If
End Sub

This does not work and gives an error on "If Evaluate..." line. Could
someone help please.

I am also wondering if it can accomodate when one or both the values
are #NA type of errors.

Thanks
Utkarsh


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Comparing two ranges

Thanks a ton! this works well!

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
Comparing 2 ranges? calberto22 Excel Discussion (Misc queries) 3 October 13th 07 03:19 AM
comparing two text ranges crainone Excel Discussion (Misc queries) 5 June 17th 07 09:12 PM
Comparing ranges: ben simpson Excel Discussion (Misc queries) 1 March 8th 06 04:35 AM
Comparing ranges Robert1 Excel Programming 0 December 1st 05 06:48 PM
How to : Comparing Two Ranges lockwood7 Excel Worksheet Functions 3 August 3rd 05 01:43 PM


All times are GMT +1. The time now is 11:26 PM.

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"