if statement help

birdman

Board Regular
Joined
Oct 11, 2005
Messages
187
does anyone know the code that if an if statement is true then go back to a certain point in the code and start from there again?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I'm a bit confused.
I assume that you are wanting to do the IF statement again but with a different value or different cell etc. (If you kept using the same value, which returns true, then you'll have a never ending argument!)

If I'm right, then I guess you are after a looping macro. Tell us what you are after and we'll be in a better position to help.
 
Upvote 0
Look at the Goto Statements in the Help Function

ie

Code:
StartAgain:

If YourValue = True Then GoTo StartAgain
 
Upvote 0
i have a userform that has a section to select one or more text files to be analyzed using a listbox. on the same userform, the user can select a number of checkboxes. these checkboxes are connected to operations that can be performed on the text files.

so if you select 2 text files and a few of the checkboxes, the first text file is opened and analyzed, then the second file is opened and analyzed. this is done using a for loop

i am now attempting to incorporate a text file splitter into my program (in case the text file is over 32000 rows - the max for graphing). after the file is split into 2 separate workbooks, the second half is closed, and the first half is analyzed. then i need the second half to be opened again and analyzed.

i can get the first half to be analyzed, but once that is done i need to open the second half and go back to a certain point in the for loop and continue the analysis from there before i move onto the next text file in my listbox. hope this makes sense.

thanks for the responses
 
Upvote 0
I agree with the answers provided so far. (Depending on what you're doing), a loop is likely the way to go. To answer your question though, the code might look something like this.
Code:
Sub Demo()
Dim SomeStuff
Dim SomeMoreStuff

Some code here

StartAgain:
  Some code here
  Some more code here
  If (my if statement) Then
    GoTo StartAgain
  Else
    Whatever you want if it's not true.
  End If
  
End Sub
A loop (if possible) is generally more preferred to using GoTo statements, especially several of them.
 
Upvote 0
for those of you who are interested. i used goto within a for loop. here is an example.
Code:
Dim test as Integer
If test = 0 Then
     'code here
     test = 1
     GoTo StartAgain
End If
StartAgain would be earlier in the for loop

although it is not recommended to use the goto command, it has worked good so far.
 
Upvote 0
birdman said:
although it is not recommended to use the goto command, it has worked good so far.
I know some folks don't like to use GoTo at all, (and I guess if within reason you can avoid it you should), but when used sparingly I've never had a problem with them. (yet.) :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,228
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top