PC Review


Reply
Thread Tools Rate Thread

Can I simplify these IF statements

 
 
=?Utf-8?B?SmltIFRpYmJldHRz?=
Guest
Posts: n/a
 
      12th Apr 2007
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 With Quote
 
 
 
 
=?Utf-8?B?Um9uIENvZGVycmU=?=
Guest
Posts: n/a
 
      12th Apr 2007
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

 
Reply With Quote
 
Norman Yuan
Guest
Posts: n/a
 
      12th Apr 2007
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" <(E-Mail Removed)> wrote in message
news:2FBCE892-B1A9-475C-BBA4-(E-Mail Removed)...
>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 With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      12th Apr 2007
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 With Quote
 
=?Utf-8?B?SmltIFRpYmJldHRz?=
Guest
Posts: n/a
 
      12th Apr 2007
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" <(E-Mail Removed)> wrote in message
> news:2FBCE892-B1A9-475C-BBA4-(E-Mail Removed)...
> >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 With Quote
 
=?Utf-8?B?SmltIFRpYmJldHRz?=
Guest
Posts: n/a
 
      12th Apr 2007
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

 
Reply With Quote
 
=?Utf-8?B?Um9uIENvZGVycmU=?=
Guest
Posts: n/a
 
      12th Apr 2007
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

 
Reply With Quote
 
=?Utf-8?B?SmltIFRpYmJldHRz?=
Guest
Posts: n/a
 
      12th Apr 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested IF statements - simplify? Mark K. Microsoft Excel Programming 4 3rd Sep 2006 02:52 AM
operator statements, shorting when reusing one of the statements? KR Microsoft Excel Programming 1 4th Aug 2005 06:20 PM
please help simplify acarril Microsoft Excel Programming 0 27th Sep 2004 07:45 PM
please help simplify acarril Microsoft Excel Programming 1 27th Sep 2004 04:45 PM
please help simplify acarril Microsoft Excel Programming 1 21st Sep 2004 07:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:17 PM.