How to exit a While loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mitsy
    New Member
    • Sep 2007
    • 9

    #1

    How to exit a While loop

    i have to use something to END a program. how ever using end isnt workin!

    Code:
    While ActiveSheet.Cells(Row, COL_DATA) > 0
    
          ActiveSheet.Cells(ROW_NUMDISKS, COL_DATA) = InitialRadiusValue + NewRadiusValue
          InitialRadiusValue = InitialRadiusValue + NewRadiusValue
          Row = Row + 1
          
            If ActiveSheet.Cells(Row, COL_DATA) < 0 Then
               ActiveSheet.Cells(ROW_NUMDISKS, COL_DATA) = "Sorry, one or more cells do not contain a real radius"
            End If
            
                If Not IsNumeric(ActiveSheet.Cells(Row, COL_DATA)) Then
                  ActiveSheet.Cells(ROW_NUMDISKS, COL_DATA) = "Sorry, one or more cells do not contain a real radius"
                 End If
           End

    so basically...if the values entered aren't numbers i want the program to STOP! how do i do tht???

    using Mircrosoft excell 2003, vba

    thanks
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Try to use exit sub for the purpose.

    Comment

    • hariharanmca
      Top Contributor
      • Dec 2006
      • 1977

      #3
      You want to end the application or end the method (exit method)?

      Comment

      • mitsy
        New Member
        • Sep 2007
        • 9

        #4
        Originally posted by hariharanmca
        You want to end the application or end the method (exit method)?

        i want to end the method. STOP the WHILE statement!

        Comment

        • mitsy
          New Member
          • Sep 2007
          • 9

          #5
          Originally posted by debasisdas
          Try to use exit sub for the purpose.

          exit sub doesn work either :'(

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by mitsy
            exit sub doesn work either :'(
            Use Exit Do. If necessary, change the While...Wend structure to Do While...Loop.

            Comment

            • mitsy
              New Member
              • Sep 2007
              • 9

              #7
              Ahhhhhhhhhh!!!! !!!!!!!!!!!!!!! !!! Nope nothing nothing nothing! Tried everything! NOTHING WORKS! Have I mentioned how much I hate VBA? Sorry if I offended you programers out there!
              Last edited by Killer42; Oct 5 '07, 06:46 AM.

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by mitsy
                Ahhhhhhhhhh!!!! !!!!!!!!!!!!!!! !!! Nope nothing nothing nothing! Tried everything! NOTHING WORKS! Have I mentioned how much I hate VBA? Sorry if I offended you programers out there!
                Well, I hate to contradict you, but Exit Do does work. Which means you have not tried "everything ". You must some another problem. I've often found that when you keep bouncing off a problem for too long, it often turns out that you're attacking completely the wrong thing.

                Have you tried interrupting the code and stepping through it a statement at a time, to see exactly what is happening? The debugging tools in VB are actually quite good.

                In the meantime, how about posting the full section of code here, so we can see what you have tried?

                As for being offended, that would be a bit silly. Just because one uses a tool doesn't mean everybody in the world should love that tool. I happen to think VBA is very convenient, being built into the various Office products, and has some useful capabilities. But it's certainly far from perfect. I doubt you'd find any programmer who hasn't wanted to punch in their monitor at times.

                By the way, the TSDN posting guidelines require "clear, concise English". While everybody's English naturally varies (after all, we have members from all over the world) that does mean that among other things, we expect members to refrain from using SMS-style abbreviations such as "u" for "you".

                Comment

                Working...