Nested IF statements - simplify?

  • Thread starter Thread starter Mark K.
  • Start date Start date
M

Mark K.

Hi,

Just looking for a way to cut down on some nested if statements.
Currently have the following:

If theRunner <> Empty Then
If theRunner <> "runner" Then
If theRunner <> "scr" Then
Range("H1").Select
Do Until Trim(LCase(ActiveCell)) = theRunner
ActiveCell.Offset(1, 0).Select
Loop
wOutSht.Cells(runnerOSet, "AJ").Value = ActiveCell.Offset(0, -7).Value
End If
End If
End If

Is there a way to get the first 3 lines into 1? Basically want it to
ignore empty cells and those containing the strings "runner" or "scr".

TIA
 
I like this:

if therunner = "" _
or therunner = "runner" _
or therunner = "scr" then
'do nothing
else
'do the real work
end if

But you could use:

if therunner <> "" _
and therunner <> "runner" _
and therunner <> "scr" then
'do the real work
end if

But sometimes with And/negatives, it gets confusing (well, for me, anyway).
 
untested:

Sub test()
If theRunner <> Empty And theRunner <> "runner" And theRunner <> "scr" Then
Range("H1").Select
Do Until Trim(LCase(ActiveCell)) = theRunner
ActiveCell.Offset(1, 0).Select
Loop
wOutSht.Cells(runnerOSet, "AJ").Value = ActiveCell.Offset(0, -7).Value
End If
End Sub
 
That's where I went wrong, tried using AND but didn't include the extra
"theRunner <>" between each

Cheers
 
That's why I like to use the "or's" and ='s. And just put the code in the Else
portion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top