Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Can I simplify these IF statements

I have a named range "NUMBER". When its value is 5, 10, 15, 20, 25, 30 or 35
I want to run sub CopyAggregate(). Is there a more elegant way to write this?

If Range("NUMBER").Value = 5 Then CopyAggregate
ElseIf Range("NUMBER").Value = 10 Then CopyAggregate
ElseIf Range("NUMBER").Value = 15 Then CopyAggregate
ElseIf Range("NUMBER").Value = 20 Then CopyAggregate
ElseIf Range("NUMBER").Value = 25 Then CopyAggregate
ElseIf Range("NUMBER").Value = 30 Then CopyAggregate
ElseIf Range("NUMBER").Value = 35 Then CopyAggregate
End If

Thanks for any suggestions.
--
Jim T
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 698
Default Can I simplify these IF statements

Try something like this:

'--------Start of Code------------
Select Case Range("number").Value
Case Is = 5, 10, 15, 20, 25, 30
CopyAggregate
Case Else
MsgBox "Does not meet criteria"
End Select
'--------End of Code------------

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"Jim Tibbetts" wrote:

I have a named range "NUMBER". When its value is 5, 10, 15, 20, 25, 30 or 35
I want to run sub CopyAggregate(). Is there a more elegant way to write this?

If Range("NUMBER").Value = 5 Then CopyAggregate
ElseIf Range("NUMBER").Value = 10 Then CopyAggregate
ElseIf Range("NUMBER").Value = 15 Then CopyAggregate
ElseIf Range("NUMBER").Value = 20 Then CopyAggregate
ElseIf Range("NUMBER").Value = 25 Then CopyAggregate
ElseIf Range("NUMBER").Value = 30 Then CopyAggregate
ElseIf Range("NUMBER").Value = 35 Then CopyAggregate
End If

Thanks for any suggestions.
--
Jim T

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Can I simplify these IF statements

SELECT Case Range("NUMBER").Value
Case 5, 10, 15, 20, 25, 30, 35
CopyAggregate
Case Else
'Do something or do nothing
End Select

"Jim Tibbetts" wrote in message
...
I have a named range "NUMBER". When its value is 5, 10, 15, 20, 25, 30 or
35
I want to run sub CopyAggregate(). Is there a more elegant way to write
this?

If Range("NUMBER").Value = 5 Then CopyAggregate
ElseIf Range("NUMBER").Value = 10 Then CopyAggregate
ElseIf Range("NUMBER").Value = 15 Then CopyAggregate
ElseIf Range("NUMBER").Value = 20 Then CopyAggregate
ElseIf Range("NUMBER").Value = 25 Then CopyAggregate
ElseIf Range("NUMBER").Value = 30 Then CopyAggregate
ElseIf Range("NUMBER").Value = 35 Then CopyAggregate
End If

Thanks for any suggestions.
--
Jim T



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Can I simplify these IF statements

maybe like this

With Range("NUMBER")
If (.Value Mod 5 = 0) And (.Value 0) And (.Value < 36) Then
CopyAggregate
End With


--
Hope that helps.

Vergel Adriano


"Jim Tibbetts" wrote:

I have a named range "NUMBER". When its value is 5, 10, 15, 20, 25, 30 or 35
I want to run sub CopyAggregate(). Is there a more elegant way to write this?

If Range("NUMBER").Value = 5 Then CopyAggregate
ElseIf Range("NUMBER").Value = 10 Then CopyAggregate
ElseIf Range("NUMBER").Value = 15 Then CopyAggregate
ElseIf Range("NUMBER").Value = 20 Then CopyAggregate
ElseIf Range("NUMBER").Value = 25 Then CopyAggregate
ElseIf Range("NUMBER").Value = 30 Then CopyAggregate
ElseIf Range("NUMBER").Value = 35 Then CopyAggregate
End If

Thanks for any suggestions.
--
Jim T

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Can I simplify these IF statements

Norman - Thanks for the help. I have never seen Select Case before. I think
it will work just fine.
--
Jim T


"Norman Yuan" wrote:

SELECT Case Range("NUMBER").Value
Case 5, 10, 15, 20, 25, 30, 35
CopyAggregate
Case Else
'Do something or do nothing
End Select

"Jim Tibbetts" wrote in message
...
I have a named range "NUMBER". When its value is 5, 10, 15, 20, 25, 30 or
35
I want to run sub CopyAggregate(). Is there a more elegant way to write
this?

If Range("NUMBER").Value = 5 Then CopyAggregate
ElseIf Range("NUMBER").Value = 10 Then CopyAggregate
ElseIf Range("NUMBER").Value = 15 Then CopyAggregate
ElseIf Range("NUMBER").Value = 20 Then CopyAggregate
ElseIf Range("NUMBER").Value = 25 Then CopyAggregate
ElseIf Range("NUMBER").Value = 30 Then CopyAggregate
ElseIf Range("NUMBER").Value = 35 Then CopyAggregate
End If

Thanks for any suggestions.
--
Jim T






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Can I simplify these IF statements

Ron - Thanks for the help. I have never seen Select Case before. I think it
will work just fine.
--
Jim T


"Ron Coderre" wrote:

Try something like this:

'--------Start of Code------------
Select Case Range("number").Value
Case Is = 5, 10, 15, 20, 25, 30
CopyAggregate
Case Else
MsgBox "Does not meet criteria"
End Select
'--------End of Code------------

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"Jim Tibbetts" wrote:

I have a named range "NUMBER". When its value is 5, 10, 15, 20, 25, 30 or 35
I want to run sub CopyAggregate(). Is there a more elegant way to write this?

If Range("NUMBER").Value = 5 Then CopyAggregate
ElseIf Range("NUMBER").Value = 10 Then CopyAggregate
ElseIf Range("NUMBER").Value = 15 Then CopyAggregate
ElseIf Range("NUMBER").Value = 20 Then CopyAggregate
ElseIf Range("NUMBER").Value = 25 Then CopyAggregate
ElseIf Range("NUMBER").Value = 30 Then CopyAggregate
ElseIf Range("NUMBER").Value = 35 Then CopyAggregate
End If

Thanks for any suggestions.
--
Jim T

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 698
Default Can I simplify these IF statements

I'm glad I could help.....and thanks much for the feedback!


***********
Regards,
Ron

XL2002, WinXP


"Jim Tibbetts" wrote:

Ron - Thanks for the help. I have never seen Select Case before. I think it
will work just fine.
--
Jim T


"Ron Coderre" wrote:

Try something like this:

'--------Start of Code------------
Select Case Range("number").Value
Case Is = 5, 10, 15, 20, 25, 30
CopyAggregate
Case Else
MsgBox "Does not meet criteria"
End Select
'--------End of Code------------

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"Jim Tibbetts" wrote:

I have a named range "NUMBER". When its value is 5, 10, 15, 20, 25, 30 or 35
I want to run sub CopyAggregate(). Is there a more elegant way to write this?

If Range("NUMBER").Value = 5 Then CopyAggregate
ElseIf Range("NUMBER").Value = 10 Then CopyAggregate
ElseIf Range("NUMBER").Value = 15 Then CopyAggregate
ElseIf Range("NUMBER").Value = 20 Then CopyAggregate
ElseIf Range("NUMBER").Value = 25 Then CopyAggregate
ElseIf Range("NUMBER").Value = 30 Then CopyAggregate
ElseIf Range("NUMBER").Value = 35 Then CopyAggregate
End If

Thanks for any suggestions.
--
Jim T

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Can I simplify these IF statements

Thanks Vergel. I've been looking in VB help trying to get my brain around the
Mod operator. I don't understand how it works yet. I will keep trying.
--
Jim T


"Vergel Adriano" wrote:

maybe like this

With Range("NUMBER")
If (.Value Mod 5 = 0) And (.Value 0) And (.Value < 36) Then
CopyAggregate
End With


--
Hope that helps.

Vergel Adriano


"Jim Tibbetts" wrote:

I have a named range "NUMBER". When its value is 5, 10, 15, 20, 25, 30 or 35
I want to run sub CopyAggregate(). Is there a more elegant way to write this?

If Range("NUMBER").Value = 5 Then CopyAggregate
ElseIf Range("NUMBER").Value = 10 Then CopyAggregate
ElseIf Range("NUMBER").Value = 15 Then CopyAggregate
ElseIf Range("NUMBER").Value = 20 Then CopyAggregate
ElseIf Range("NUMBER").Value = 25 Then CopyAggregate
ElseIf Range("NUMBER").Value = 30 Then CopyAggregate
ElseIf Range("NUMBER").Value = 35 Then CopyAggregate
End If

Thanks for any suggestions.
--
Jim T

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
I need to simplify this... j5b9721 Excel Worksheet Functions 5 July 23rd 09 09:03 AM
Nested IF statements - simplify? Mark K. Excel Programming 4 September 3rd 06 02:52 AM
Simplify ccl28[_10_] Excel Programming 1 August 15th 06 10:43 AM
A way to simplify this please Larry Empey[_2_] Excel Programming 3 July 1st 06 01:04 AM
operator statements, shorting when reusing one of the statements? KR Excel Programming 1 August 4th 05 06:20 PM


All times are GMT +1. The time now is 06:58 AM.

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

About Us

"It's about Microsoft Excel"