ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   NEED HELP with simple function (https://www.excelbanter.com/excel-programming/368717-need-help-simple-function.html)

[email protected]

NEED HELP with simple function
 
This is my first time ever programming with VBA and I figured that
creating a function that sums up the number of items that fit a couple
of criteria wouldn't be very hard. However, this is proving to be more
difficult for me than I thought. This is what I have, but it returns a
#VALUE! error in the hosting cell:

Function OtherINLDue(INL1() As String, Category1() As String, INL2() As
String, Category2() As String)

Dim i As Integer
Dim totalDue As Integer

For i = 0 To UBound(INL1)

If Category1(i) = "LN2" Or Category1(i) = "LN4" Then
If UPPER(Left(INL1(i), 3)) < "EKT" And UPPER(Left(INL1(i), 2))
< "NT" And UPPER(Left(INL1(i), 2)) < "TM" And UPPER(Left(INL1(i), 2))
< "FC" And UPPER(Left(INL1(i), 5)) < "WFFOD" And UPPER(Left(INL1(i),
5)) < "CEDDS" And UPPER(Left(INL1(i), 4)) < "PROD" And
UPPER(Left(INL1(i), 2)) < "SM" And UPPER(Left(INL1(i), 2)) < "SS" And
UPPER(Left(INL1(i), 2)) < "TS" Then
totalDue = totalDue + 1
End If

Next i

For i = 0 To UBound(INL2)

If Category2(i) = "LN2" Or Category2(i) = "LN4" Then
If UPPER(Left(INL2(i), 3)) < "EKT" And UPPER(Left(INL2(i), 2))
< "NT" And UPPER(Left(INL2(i), 2)) < "TM" And UPPER(Left(INL2(i), 2))
< "FC" And UPPER(Left(INL2(i), 5)) < "WFFOD" And UPPER(Left(INL2(i),
5)) < "CEDDS" And UPPER(Left(INL2(i), 4)) < "PROD" And
UPPER(Left(INL2(i), 2)) < "SM" And UPPER(Left(INL2(i), 2)) < "SS" And
UPPER(Left(INL2(i), 2)) < "TS" Then
totalDue = totalDue + 1
End If

Next i

OtherINLDue = totalDue

End Function

Any Help would be appreciated


Bob Phillips

NEED HELP with simple function
 
What exactly are you tying to test, and for what? Your code confuses me.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ups.com...
This is my first time ever programming with VBA and I figured that
creating a function that sums up the number of items that fit a couple
of criteria wouldn't be very hard. However, this is proving to be more
difficult for me than I thought. This is what I have, but it returns a
#VALUE! error in the hosting cell:

Function OtherINLDue(INL1() As String, Category1() As String, INL2() As
String, Category2() As String)

Dim i As Integer
Dim totalDue As Integer

For i = 0 To UBound(INL1)

If Category1(i) = "LN2" Or Category1(i) = "LN4" Then
If UPPER(Left(INL1(i), 3)) < "EKT" And UPPER(Left(INL1(i), 2))
< "NT" And UPPER(Left(INL1(i), 2)) < "TM" And UPPER(Left(INL1(i), 2))
< "FC" And UPPER(Left(INL1(i), 5)) < "WFFOD" And UPPER(Left(INL1(i),
5)) < "CEDDS" And UPPER(Left(INL1(i), 4)) < "PROD" And
UPPER(Left(INL1(i), 2)) < "SM" And UPPER(Left(INL1(i), 2)) < "SS" And
UPPER(Left(INL1(i), 2)) < "TS" Then
totalDue = totalDue + 1
End If

Next i

For i = 0 To UBound(INL2)

If Category2(i) = "LN2" Or Category2(i) = "LN4" Then
If UPPER(Left(INL2(i), 3)) < "EKT" And UPPER(Left(INL2(i), 2))
< "NT" And UPPER(Left(INL2(i), 2)) < "TM" And UPPER(Left(INL2(i), 2))
< "FC" And UPPER(Left(INL2(i), 5)) < "WFFOD" And UPPER(Left(INL2(i),
5)) < "CEDDS" And UPPER(Left(INL2(i), 4)) < "PROD" And
UPPER(Left(INL2(i), 2)) < "SM" And UPPER(Left(INL2(i), 2)) < "SS" And
UPPER(Left(INL2(i), 2)) < "TS" Then
totalDue = totalDue + 1
End If

Next i

OtherINLDue = totalDue

End Function

Any Help would be appreciated





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com