Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If is present exit sub (2000 sr 1)

    I have this var DATATAB as string and it can assume the value similar:
    4500-5100-06302230-12/2004
    4500-5100-10000184-06/2005
    4500-5100-10053158-09/2005
    4500-5100-10053158-10/2005
    4500-5100-13813342-01/2004
    4500-5100-13813342-02/2004


    The column G (start range G3:G65536) contain many value similar

    4500-5100-06302230-12/2004
    4500-5100-10000184-06/2005
    4500-5100-10053158-09/2005
    4500-5100-10053158-10/2005
    4500-5100-13813342-01/2004
    4500-5100-13813342-02/2004

    i would want to controll, before goto the next line of macro, if is present into column G the value 4500-5100-06302230-12/2004, and if is present exit sub, else goto the next line of macro...
    How to controll this?

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: If is present exit sub (2000 sr 1)

    To exit sub, use the Exit Sub statement:
    <pre> dim c as Range
    for each c in ActiveSheet.UsedRange.Columns(7).cells
    if c.Text = DataTab then exit sub
    ' stuff to do
    next c
    </pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If is present exit sub (2000 sr 1)

    Something like this:

    Option Explicit

    Sub test()
    Dim oFound As Range
    On Error Resume Next
    Set oFound = ActiveSheet.Range("G1").EntireColumn.Find("4500-5100-06302230-12/2004", LookIn:=xlFormulas)
    If oFound Is Nothing Then
    Exit Sub
    Else
    'do other things here
    MsgBox "Found!"
    End If
    End Sub
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

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