Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Adding IF statement to custom function (VBA)?

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!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Adding IF statement to custom function (VBA)?

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

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Adding IF statement to custom function (VBA)?

What was cycleNumber when "it didn't do anything"?

What happened to NextInspection?

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

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
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
Adding custom list and text boxes to the custom tool bar from Excel C API Mousam Excel Discussion (Misc queries) 0 August 7th 07 09:19 AM
Custom Function - Adding Help Information Tom Ogilvy Excel Programming 0 April 14th 05 03:47 PM
Adding a 3rd IF statement ?? yh73090[_5_] Excel Programming 3 October 17th 04 05:57 PM
Adding a 3rd IF statement ?? yh73090[_6_] Excel Programming 0 October 17th 04 04:50 AM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM


All times are GMT +1. The time now is 01:55 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"