Consulting

Results 1 to 5 of 5

Thread: Sleeper: Input Box asks for input twice!

  1. #1
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location

    Sleeper: Input Box asks for input twice!

    This is making a bad day even worse!

    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.

    Am I missing something obvious here?

    Regards
    Iain - XL2010 on Windows 7

  2. #2
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    I tried it with Excel97 and it runs fine from the macro dialogue.

    Daniel

  3. #3
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Hi Iain,

    Seems to work OK with 2003 too.

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

  4. #4
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Works fine on 2000 as well

    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  5. #5
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location
    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
    Iain - XL2010 on Windows 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •