+ Reply to Thread
Results 1 to 3 of 3

End sub early if mismatch

  1. #1
    achidsey
    Guest

    End sub early if mismatch


    My code (below) uses a For Each..Next loop with an If section to check if
    two columns of data match.

    If there is a mismatch, code displays a message box.

    I want to add a line that ends the procedure if a mismatch is found.

    What code would do this?


    Sub CompareLists()

    Cells.Find(What:="Open Positions In Current Year").Offset(1).Select
    Range(Selection, Selection.End(xlDown)).Select

    Set CurSymbols = Selection

    Cells.Find(What:="PASymbol").Select
    Set PASymbol = Selection

    For Each Sym In CurSymbols

    If Sym <> Cells(Sym.Row, PASymbol.Column) Then

    MsgBox "Mismatch on " & Sym

    '*** Add code here to end procedure if there is a mismatch***


    End If

    Next Sym

    MsgBox "Symbol Lists Match"

    End Sub


    Thanks in advance,
    Alan

    --
    achidsey

  2. #2
    Gary''s Student
    Guest

    RE: End sub early if mismatch

    Exit Sub
    --
    Gary''s Student


    "achidsey" wrote:

    >
    > My code (below) uses a For Each..Next loop with an If section to check if
    > two columns of data match.
    >
    > If there is a mismatch, code displays a message box.
    >
    > I want to add a line that ends the procedure if a mismatch is found.
    >
    > What code would do this?
    >
    >
    > Sub CompareLists()
    >
    > Cells.Find(What:="Open Positions In Current Year").Offset(1).Select
    > Range(Selection, Selection.End(xlDown)).Select
    >
    > Set CurSymbols = Selection
    >
    > Cells.Find(What:="PASymbol").Select
    > Set PASymbol = Selection
    >
    > For Each Sym In CurSymbols
    >
    > If Sym <> Cells(Sym.Row, PASymbol.Column) Then
    >
    > MsgBox "Mismatch on " & Sym
    >
    > '*** Add code here to end procedure if there is a mismatch***
    >
    >
    > End If
    >
    > Next Sym
    >
    > MsgBox "Symbol Lists Match"
    >
    > End Sub
    >
    >
    > Thanks in advance,
    > Alan
    >
    > --
    > achidsey


  3. #3
    achidsey
    Guest

    RE: End sub early if mismatch


    Gary''s Student,

    Simple enough.

    Thanks

    --
    achidsey


    "Gary''s Student" wrote:

    > Exit Sub
    > --
    > Gary''s Student
    >
    >
    > "achidsey" wrote:
    >
    > >
    > > My code (below) uses a For Each..Next loop with an If section to check if
    > > two columns of data match.
    > >
    > > If there is a mismatch, code displays a message box.
    > >
    > > I want to add a line that ends the procedure if a mismatch is found.
    > >
    > > What code would do this?
    > >
    > >
    > > Sub CompareLists()
    > >
    > > Cells.Find(What:="Open Positions In Current Year").Offset(1).Select
    > > Range(Selection, Selection.End(xlDown)).Select
    > >
    > > Set CurSymbols = Selection
    > >
    > > Cells.Find(What:="PASymbol").Select
    > > Set PASymbol = Selection
    > >
    > > For Each Sym In CurSymbols
    > >
    > > If Sym <> Cells(Sym.Row, PASymbol.Column) Then
    > >
    > > MsgBox "Mismatch on " & Sym
    > >
    > > '*** Add code here to end procedure if there is a mismatch***
    > >
    > >
    > > End If
    > >
    > > Next Sym
    > >
    > > MsgBox "Symbol Lists Match"
    > >
    > > End Sub
    > >
    > >
    > > Thanks in advance,
    > > Alan
    > >
    > > --
    > > achidsey


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1