Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Nested IF statements - simplify?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Nested IF statements - simplify?

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).




"Mark K." wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Nested IF statements - simplify?

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

--


Gary


"Mark K." wrote in message
...
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Nested IF statements - simplify?

That's where I went wrong, tried using AND but didn't include the extra
"theRunner <" between each

Cheers

GKeramidas wrote:
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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Nested IF statements - simplify?

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



"Mark K." wrote:

That's where I went wrong, tried using AND but didn't include the extra
"theRunner <" between each

Cheers

GKeramidas wrote:
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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested IF statements NancyB Excel Discussion (Misc queries) 3 May 5th 09 06:19 PM
Nested IF statements TwoDot Excel Worksheet Functions 4 February 8th 07 12:17 AM
Nested IF statements misstrious Excel Programming 5 February 26th 06 04:08 PM
Nested If Statements Jasmine Excel Worksheet Functions 2 January 26th 06 03:47 PM
what is the max no. of nested Ifs can an If Statements have in EXC StevenE Excel Discussion (Misc queries) 1 June 27th 05 03:03 PM


All times are GMT +1. The time now is 07:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"