PDA

View Full Version : Sleeper: Input Box asks for input twice!



Glaswegian
06-09-2005, 04:00 AM
This is making a bad day even worse!:banghead:

I'm using this code to run a quick match against two columns - it works great and highlights differences, which is all I need.

But - when I run this code from the macro dialogue box, it asks for both ranges twice. When I step through the code in the VB Editor it only asks once.



Sub FindDuplicates() 'matches against 2 cols
Dim Rng1 As Range 'matches first cell in first range against each cell in second range
Dim Rng2 As Range
Dim bMatch As Boolean
Dim origRng As Range
Dim compRng As Range
On Error Resume Next
Set origRng = Application.InputBox("Choose the first range", "Range 1", Type:=8)
If origRng Is Nothing Then Exit Sub
Set compRng = Application.InputBox("Choose the second range", "Range 2", Type:=8)
If compRng Is Nothing Then Exit Sub
For Each Rng1 In origRng
bMatch = False
For Each Rng2 In compRng
If Rng1 = Rng2 Then
bMatch = True
Rng2.Interior.ColorIndex = 4
End If
Next Rng2
If bMatch = False Then
Rng1.Interior.ColorIndex = 3
End If
Next Rng1
End Sub


I can't see any obvious reason why this should happen. :dunno

Am I missing something obvious here?

Regards

Steiner
06-09-2005, 04:41 AM
I tried it with Excel97 and it runs fine from the macro dialogue.

Daniel

Richie(UK)
06-09-2005, 05:26 AM
Hi Iain,

Seems to work OK with 2003 too.

Is the code you are using exactly as posted? Any other subs involved?

johnske
06-09-2005, 05:34 AM
Works fine on 2000 as well :)

John

Glaswegian
06-09-2005, 05:59 AM
Hi all

Thanks for your replies

We've recently moved over to XP from 97 - this used to work fine on 97 for me too. There are no other routines involved.

It's really just a nuisance - maybe I should just print out and compare manually!!

Regards