ItIsHardToProgram
Technical User
Hello once again everyone,
I am currently working on a Function for one of my worksheet. This is what the function should be doing:
Take a range of GL accounts delimited by "..", i.e. 40100..40200
With that range, look up in a tab to see if theres an account that fits between these 2.
Return the sum of all the values foud in the corresponding criteria.
This is what i built, and I believe it works, but I get a Type incompatibility, error 13, on my split.
Ive tried calling the array of the split, dosnt work, ive tried turning the type of variable that holds the split in a table, dosnt work... Basically I need to find out if I am doing anything wrong, maybe split won't work for this?
Here is my function:
N.B.* the function is currently a sub for testing (debug.prints etc...) the lower part of the sub in comment will also be part of the function.
As you can see, the part highlighted is where it returns the error, Also, when the code is like this, it wont let me fire because LookUpSplit is a table, if i turn it in a value and scrap my LookUpSpliT(1) and (2) it returns an incompatibility error (13).
The 2nd part that is in bold is because I am not sure of how to call the range in a lookup, do I have to reference the sheet, like this: Sheets(location)
Location in this situation would be the following string 'My sheet'!$A$45:$B$55.
Thanks for your help every one.
"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.
I am currently working on a Function for one of my worksheet. This is what the function should be doing:
Take a range of GL accounts delimited by "..", i.e. 40100..40200
With that range, look up in a tab to see if theres an account that fits between these 2.
Return the sum of all the values foud in the corresponding criteria.
This is what i built, and I believe it works, but I get a Type incompatibility, error 13, on my split.
Ive tried calling the array of the split, dosnt work, ive tried turning the type of variable that holds the split in a table, dosnt work... Basically I need to find out if I am doing anything wrong, maybe split won't work for this?
Here is my function:
N.B.* the function is currently a sub for testing (debug.prints etc...) the lower part of the sub in comment will also be part of the function.
Code:
Sub YlookUp( _
GLrange As String, _
location As String, _
ActColumn As Integer)
On Error GoTo ErrorHandler
Dim LookUpSplit(2) As String
Dim GLtab As Long
Dim i As Integer
Dim LookUpSplit1 As Long
Dim LookUpSplit2 As Long
Dim FoundValue As Double
'Délimitation des bornes de lookup
[highlight]LookUpSplit = Split(GLrange, "..")[/highlight]
For i = 1 To 10
GLtab = Sheets("Accts").Cells(i, 1)
'si un compte correspond au range, alors additionne le chiffre de la colone au reste
If GLtab > LookUpSplit(1) And GLtab < LookUpSplit(2) Then
FoundValue = FoundValue + Application.VLookup(GLtab, [b]Range(sheets.location)[/b], ActColumn, 0)
End If
Next i
'YlookUp = FoundValue
'If IsError(YlookUp) Then
' YlookUp = "Error"
' MsgBox ("You have encountered an error with value " & _
' GLrange & " " & _
' location)
'End If
ErrorHandler:
MsgBox (Err & " " & Error(Err))
End Sub
As you can see, the part highlighted is where it returns the error, Also, when the code is like this, it wont let me fire because LookUpSplit is a table, if i turn it in a value and scrap my LookUpSpliT(1) and (2) it returns an incompatibility error (13).
The 2nd part that is in bold is because I am not sure of how to call the range in a lookup, do I have to reference the sheet, like this: Sheets(location)
Location in this situation would be the following string 'My sheet'!$A$45:$B$55.
Thanks for your help every one.
"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.