+ Reply to Thread
Results 1 to 7 of 7

Stumped

  1. #1
    Andibevan
    Guest

    Stumped

    Hi,

    If I try the following I get a Next without For error - Is it possible to do
    something like this?


    Sub test_loop()

    For k = 1 To 5

    If k = 3 Then
    Next k
    Else
    MsgBox k
    End If

    Next k
    End Sub

    TIA

    Andy



  2. #2
    Kevin O'Neill
    Guest

    Re: Stumped

    What are you trying to do exactly?


  3. #3
    Tom Ogilvy
    Guest

    Re: Stumped

    Sub test_loop()

    For k = 1 To 5

    If k <> 3 Then
    MsgBox k
    End If

    Next k
    End Sub

    --
    Regards,
    Tom Ogilvy


    "Andibevan" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi,
    >
    > If I try the following I get a Next without For error - Is it possible to

    do
    > something like this?
    >
    >
    > Sub test_loop()
    >
    > For k = 1 To 5
    >
    > If k = 3 Then
    > Next k
    > Else
    > MsgBox k
    > End If
    >
    > Next k
    > End Sub
    >
    > TIA
    >
    > Andy
    >
    >




  4. #4
    Gary Keramidas
    Guest

    Re: Stumped

    this will even skip 3, but don't know what you're trying to accomplish

    Sub test_loop()
    Dim k As Long
    For k = 1 To 5

    If k = 3 Then
    'do nothing
    Else
    MsgBox k
    End If

    Next k
    End Sub


    --


    Gary


    "Andibevan" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi,
    >
    > If I try the following I get a Next without For error - Is it possible to
    > do
    > something like this?
    >
    >
    > Sub test_loop()
    >
    > For k = 1 To 5
    >
    > If k = 3 Then
    > Next k
    > Else
    > MsgBox k
    > End If
    >
    > Next k
    > End Sub
    >
    > TIA
    >
    > Andy
    >
    >




  5. #5
    Andibevan
    Guest

    Re: Stumped

    Sorry - I essentially was wondering whether it was possible to include two
    'Next' Statements in one For loop?

    "Gary Keramidas" <GKeramidasATmsn.com> wrote in message
    news:[email protected]...
    > this will even skip 3, but don't know what you're trying to accomplish
    >
    > Sub test_loop()
    > Dim k As Long
    > For k = 1 To 5
    >
    > If k = 3 Then
    > 'do nothing
    > Else
    > MsgBox k
    > End If
    >
    > Next k
    > End Sub
    >
    >
    > --
    >
    >
    > Gary
    >
    >
    > "Andibevan" <[email protected]> wrote in message
    > news:%[email protected]...
    > > Hi,
    > >
    > > If I try the following I get a Next without For error - Is it possible

    to
    > > do
    > > something like this?
    > >
    > >
    > > Sub test_loop()
    > >
    > > For k = 1 To 5
    > >
    > > If k = 3 Then
    > > Next k
    > > Else
    > > MsgBox k
    > > End If
    > >
    > > Next k
    > > End Sub
    > >
    > > TIA
    > >
    > > Andy
    > >
    > >

    >
    >




  6. #6
    Dominic
    Guest

    Re: Stumped

    No, it is not.

    It would help to know what you are trying to do, as Kevin O'Neill asked.

    If you are trying to increase k by two through using two next statements,
    then use step 2 in your for loop.

    ex. for k = 1 to 5 step 2




    "Andibevan" wrote:

    > Sorry - I essentially was wondering whether it was possible to include two
    > 'Next' Statements in one For loop?
    >
    > "Gary Keramidas" <GKeramidasATmsn.com> wrote in message
    > news:[email protected]...
    > > this will even skip 3, but don't know what you're trying to accomplish
    > >
    > > Sub test_loop()
    > > Dim k As Long
    > > For k = 1 To 5
    > >
    > > If k = 3 Then
    > > 'do nothing
    > > Else
    > > MsgBox k
    > > End If
    > >
    > > Next k
    > > End Sub
    > >
    > >
    > > --
    > >
    > >
    > > Gary
    > >
    > >
    > > "Andibevan" <[email protected]> wrote in message
    > > news:%[email protected]...
    > > > Hi,
    > > >
    > > > If I try the following I get a Next without For error - Is it possible

    > to
    > > > do
    > > > something like this?
    > > >
    > > >
    > > > Sub test_loop()
    > > >
    > > > For k = 1 To 5
    > > >
    > > > If k = 3 Then
    > > > Next k
    > > > Else
    > > > MsgBox k
    > > > End If
    > > >
    > > > Next k
    > > > End Sub
    > > >
    > > > TIA
    > > >
    > > > Andy
    > > >
    > > >

    > >
    > >

    >
    >
    >


  7. #7
    Dana DeLouis
    Guest

    Re: Stumped

    > If I try the following I get a Next without For error - Is it possible to
    > do
    > something like this?


    Hi. You have two "Next" statements, therefore your error. Here are just
    two of many ways:

    Sub test_loop1()
    Dim k As Long
    For k = 1 To 5
    If k = 3 Then
    'Remark: Do Nothing...
    Else
    MsgBox k
    End If
    Next k
    End Sub


    Sub test_loop2()
    Dim k As Long
    For k = 1 To 5
    If k <> 3 Then MsgBox k
    Next k
    End Sub

    HTH :>)
    --
    Dana DeLouis
    Win XP & Office 2003


    "Andibevan" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi,
    >
    > If I try the following I get a Next without For error - Is it possible to
    > do
    > something like this?
    >
    >
    > Sub test_loop()
    >
    > For k = 1 To 5
    >
    > If k = 3 Then
    > Next k
    > Else
    > MsgBox k
    > End If
    >
    > Next k
    > End Sub
    >
    > TIA
    >
    > Andy
    >
    >




+ 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