Do Until myString

LEXCERM

Active Member
Joined
Jun 26, 2004
Messages
314
Office Version
  1. 365
Platform
  1. Windows
Hi,

I want to be able to specify the statement directly after "Do Until" based on two possible conditions, i.e.....


If ActiveCell.Row > NewStatement Then
NewStatementLoop = "ActiveCell = """
Else
NewStatementLoop = "ActiveCell.Row = " & NewStatement
End If

Do Until NewStatementLoop


I keep getting Type Mismatch and general debug errors.

Can this be done?

Many thanks in advance. :)
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Thanks for replying slinky.

Can't post all of it, but this is the general gist:-


NewStatement = Cells.Find(What:="Test Cell").Row

If ActiveCell.Row < NewStatement Then
NewStatementLoop = "ActiveCell = """
Else
NewStatementLoop = "ActiveCell.Row = " & NewStatement
End If

Do Until NewStatementLoop
''''>>> loads of code and stuff
Loop


Code errors at the line "Do Until NewStatementLoop". I simply want to define what statement to use.
Thanks! :)
 
Upvote 0
You're suggesting that something runs until NewStatementLoop, what is NewStatementLoop?

Does it ever become True/False? Otherwise you're going to be better off with a
Code:
do until activecell.row = NewStatementLoop

or something similar..
 
Upvote 0
NewStatementLoop will either be: "ActiveCell = """, or "ActiveCell.Row = NewStatement". I want either of those two statements to follow "Do Until".

I am evaluating whether the string "Test Cell" is above or below the active cell in my routine.
 
Upvote 0
No worries and thanks for your time. There are other ways I can handle this, but I was just curious to see if we could use a variable string directly after DO UNTIL. :)
 
Upvote 0
Thanks for the link. I get the concept of the loop syntax, which is what I am trying to do here. So, it'll either be:-


Do Until ActiveCell = ""
...or...
Do Until ActiveCell.Row = 98 (which will be the NewStatementRow identifier)


At this point in the code, the cursor position is being evaluated.

Maybe I'm not explaining myself proeprly, which I apologise for. It's bright and sunny outside and that's where I wanna be!!! :)
 
Upvote 0
I see that sun shining here too!

This works for me, but I'm not sure if it'll fully comply with what you need...

Code:
Sub test()
NewStatement = Cells.Find(What:="Test Cell").Row
Do Until ActiveCell.Row = NewStatement
ActiveCell.Offset(1, 0).Select
Loop
End Sub

The loop exits at the point that the Activecell.Row value = NewStatement

So, it would make sense to encapsulate that in the IF statement verifying whether the value of NewStatement is greater than the row of the current cell.
 
Upvote 0

Forum statistics

Threads
1,203,241
Messages
6,054,326
Members
444,717
Latest member
melindanegron

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