PC Review


Reply
Thread Tools Rate Thread

Adding IF statement to custom function (VBA)?

 
 
theseandavis@gmail.com
Guest
Posts: n/a
 
      11th Oct 2006
Hey guys,

I dont know much about VBA and programming, so this may be a dumb
question

I have a custom function I created here in VBA and I need to add some
conditionality to it. Here is the part of the code I would like to
manipulate:

**************
Public Function NextInspection(SinceLastInspection, SinceLastM3,
ObjectClass, ObjectCat) As String

Dim KM As Variant
Dim CycleNumber As Integer

KM = SinceLastM3 - SinceLastInspection + 6000

CycleNumber = Round(KM / 6000, 0)

If ObjectClass = "TROL" Then

Select Case CycleNumber

Case 1 To 8: NextInspection = "MINOR-T"
Case 9: NextInspection = "MAJOR3-T"
Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"

End Select
.....
******************

What I would like to tell this to do is, for every time that
CycleNumber exceeds 9, subtract 9 (eg.9 is the max, but may potentially
exceed 9, so if it were to read 10 i would like it to instead read '1'
and return "MINOR-T")

Ive tried adding it in with my own knowledge, but I dont know how to do
it and keep getting errors. Any help is appreciated!

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      11th Oct 2006
Maybe...

Select Case CycleNumber mod 9

Case 1 To 8: NextInspection = "MINOR-T"
Case 0: NextInspection = "MAJOR3-T"
Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"

End Select

(E-Mail Removed) wrote:
>
> Hey guys,
>
> I dont know much about VBA and programming, so this may be a dumb
> question
>
> I have a custom function I created here in VBA and I need to add some
> conditionality to it. Here is the part of the code I would like to
> manipulate:
>
> **************
> Public Function NextInspection(SinceLastInspection, SinceLastM3,
> ObjectClass, ObjectCat) As String
>
> Dim KM As Variant
> Dim CycleNumber As Integer
>
> KM = SinceLastM3 - SinceLastInspection + 6000
>
> CycleNumber = Round(KM / 6000, 0)
>
> If ObjectClass = "TROL" Then
>
> Select Case CycleNumber
>
> Case 1 To 8: NextInspection = "MINOR-T"
> Case 9: NextInspection = "MAJOR3-T"
> Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"
>
> End Select
> ....
> ******************
>
> What I would like to tell this to do is, for every time that
> CycleNumber exceeds 9, subtract 9 (eg.9 is the max, but may potentially
> exceed 9, so if it were to read 10 i would like it to instead read '1'
> and return "MINOR-T")
>
> Ive tried adding it in with my own knowledge, but I dont know how to do
> it and keep getting errors. Any help is appreciated!


--

Dave Peterson
 
Reply With Quote
 
theseandavis@gmail.com
Guest
Posts: n/a
 
      11th Oct 2006
Great idea! But it didn't do anything

For a perhaps better idea of what Im trying to do, here is one of my
attempts with zero knowledge of VBA (sheepish)
.....
If ObjectClass = "TROL" Then

If CycleNumber > 9 Then
CycleNumber -9
Else: CycleNumber
End If

Select Case CycleNumber

Case 1 To 8: NextInspection = "MINOR-T"
Case 9: NextInspection = "MAJOR3-T"
Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"
End Select

Dave Peterson wrote:
> Maybe...
>
> Select Case CycleNumber mod 9
>
> Case 1 To 8: NextInspection = "MINOR-T"
> Case 0: NextInspection = "MAJOR3-T"
> Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"
>
> End Select
>
> (E-Mail Removed) wrote:
> >
> > Hey guys,
> >
> > I dont know much about VBA and programming, so this may be a dumb
> > question
> >
> > I have a custom function I created here in VBA and I need to add some
> > conditionality to it. Here is the part of the code I would like to
> > manipulate:
> >
> > **************
> > Public Function NextInspection(SinceLastInspection, SinceLastM3,
> > ObjectClass, ObjectCat) As String
> >
> > Dim KM As Variant
> > Dim CycleNumber As Integer
> >
> > KM = SinceLastM3 - SinceLastInspection + 6000
> >
> > CycleNumber = Round(KM / 6000, 0)
> >
> > If ObjectClass = "TROL" Then
> >
> > Select Case CycleNumber
> >
> > Case 1 To 8: NextInspection = "MINOR-T"
> > Case 9: NextInspection = "MAJOR3-T"
> > Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"
> >
> > End Select
> > ....
> > ******************
> >
> > What I would like to tell this to do is, for every time that
> > CycleNumber exceeds 9, subtract 9 (eg.9 is the max, but may potentially
> > exceed 9, so if it were to read 10 i would like it to instead read '1'
> > and return "MINOR-T")
> >
> > Ive tried adding it in with my own knowledge, but I dont know how to do
> > it and keep getting errors. Any help is appreciated!

>
> --
>
> Dave Peterson


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Oct 2006
What was cycleNumber when "it didn't do anything"?

What happened to NextInspection?

(E-Mail Removed) wrote:
>
> Great idea! But it didn't do anything
>
> For a perhaps better idea of what Im trying to do, here is one of my
> attempts with zero knowledge of VBA (sheepish)
> ....
> If ObjectClass = "TROL" Then
>
> If CycleNumber > 9 Then
> CycleNumber -9
> Else: CycleNumber
> End If
>
> Select Case CycleNumber
>
> Case 1 To 8: NextInspection = "MINOR-T"
> Case 9: NextInspection = "MAJOR3-T"
> Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"
> End Select
>
> Dave Peterson wrote:
> > Maybe...
> >
> > Select Case CycleNumber mod 9
> >
> > Case 1 To 8: NextInspection = "MINOR-T"
> > Case 0: NextInspection = "MAJOR3-T"
> > Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"
> >
> > End Select
> >
> > (E-Mail Removed) wrote:
> > >
> > > Hey guys,
> > >
> > > I dont know much about VBA and programming, so this may be a dumb
> > > question
> > >
> > > I have a custom function I created here in VBA and I need to add some
> > > conditionality to it. Here is the part of the code I would like to
> > > manipulate:
> > >
> > > **************
> > > Public Function NextInspection(SinceLastInspection, SinceLastM3,
> > > ObjectClass, ObjectCat) As String
> > >
> > > Dim KM As Variant
> > > Dim CycleNumber As Integer
> > >
> > > KM = SinceLastM3 - SinceLastInspection + 6000
> > >
> > > CycleNumber = Round(KM / 6000, 0)
> > >
> > > If ObjectClass = "TROL" Then
> > >
> > > Select Case CycleNumber
> > >
> > > Case 1 To 8: NextInspection = "MINOR-T"
> > > Case 9: NextInspection = "MAJOR3-T"
> > > Case Else: NextInspection = "INVALID NEST-CHECK DETAIL"
> > >
> > > End Select
> > > ....
> > > ******************
> > >
> > > What I would like to tell this to do is, for every time that
> > > CycleNumber exceeds 9, subtract 9 (eg.9 is the max, but may potentially
> > > exceed 9, so if it were to read 10 i would like it to instead read '1'
> > > and return "MINOR-T")
> > >
> > > Ive tried adding it in with my own knowledge, but I dont know how to do
> > > it and keep getting errors. Any help is appreciated!

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
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
Adding the Custom Function to a Crystal Report harshad Microsoft Dot NET 0 23rd Feb 2010 12:28 PM
Error when adding custom help file to custom function Sabotuer99 Microsoft Excel Programming 1 19th Jul 2008 01:46 PM
Re: Custom Function - Adding Help Information Tom Ogilvy Microsoft Excel Programming 0 14th Apr 2005 03:47 PM
SQL Insert statement with a custom function Chris Guld Microsoft Access Form Coding 1 20th May 2004 04:13 PM
Adding a custom function to the default excel function list DonutDel Microsoft Excel Programming 3 21st Nov 2003 03:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:31 AM.