Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default public function having array passing out to a sub dropdown

Hi all.

I'm trying to using a dropdown form menu to do some calculations that
will access a function that has an array. Please look at my code and
please point out what i'm doing wrong.

Public Function Test(j As Integer) As Single
Dim Check(20) As String
Dim Result(20) As String
Dim Upper(20) As Single
Dim Lower(20) As Single
Dim UL(20) As Single
Dim LL(20) As Single
Dim i, k, j As Integer
k = 4
i = 0
j = 0
Do Until i = 20
Check(i) = Worksheets("Sheet1").Cells(k, 3)
Upper(i) = Worksheets("Sheet1").Cells(k, 4)
Lower(i) = Worksheets("Sheet1").Cells(k, 5)

If Check(i) < "" Then
Result(j) = Check(i)
UL(j) = Upper(i)
LL(j) = Lower(i)
j = j + 1
End If
i = i + 1
k = k + 1

Loop
Test = UL(j)
End Function

Sub DropDown4_Change()
If Range("f13") = 1 Then
Application.ScreenUpdating = False
Range("c1") = Test(1)
Application.ScreenUpdating = True
End If
End Sub

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default public function having array passing out to a sub dropdown

It looks like you are trying to determine the value in column E for the last
row in column C (between rows 4 and 23) that is not empty.

Your main problem is you assign the test function the value UL(j), but j has
been incremented by 1 after you placed the last value in the array. So if
you want that last value, you should use

if j 0 then
test = UL(j-1)
else
test = 0 ' or whatever you want if the range is empty
End if
end Sub


Also, Upper and Lower are VBA functions. You should use a different name
for your Upper and Lower arrays.

--
Regards,
Tom Ogilvy





"TTran" wrote:

Hi all.

I'm trying to using a dropdown form menu to do some calculations that
will access a function that has an array. Please look at my code and
please point out what i'm doing wrong.

Public Function Test(j As Integer) As Single
Dim Check(20) As String
Dim Result(20) As String
Dim Upper(20) As Single
Dim Lower(20) As Single
Dim UL(20) As Single
Dim LL(20) As Single
Dim i, k, j As Integer
k = 4
i = 0
j = 0
Do Until i = 20
Check(i) = Worksheets("Sheet1").Cells(k, 3)
Upper(i) = Worksheets("Sheet1").Cells(k, 4)
Lower(i) = Worksheets("Sheet1").Cells(k, 5)

If Check(i) < "" Then
Result(j) = Check(i)
UL(j) = Upper(i)
LL(j) = Lower(i)
j = j + 1
End If
i = i + 1
k = k + 1

Loop
Test = UL(j)
End Function

Sub DropDown4_Change()
If Range("f13") = 1 Then
Application.ScreenUpdating = False
Range("c1") = Test(1)
Application.ScreenUpdating = True
End If
End Sub

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default public function having array passing out to a sub dropdown

I want to be able to access any number that is stored in the UL(j) or
LL(j) array after the function Test remove all the empty rows in the
UpperLimit(i) or LowerLimit(i).

I will present the user with a combo box located on the excel
worksheets.

Sub DropDown4_Change()
If Range("f13") = 1 Then
Application.ScreenUpdating = False
Range("c1") = Test(1)
Application.ScreenUpdating = True
End If
End Sub

that sub check to see which choice the user selected then i proceed to
call the test function and pull out a particular # that is stored in
the UL(j) or LL(j) array and then do some calculations.

But it doesn't matter which index # (of j) i passthrough the function
Test() I always get the last # of the array.

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
Passing an array in a user defined function Peter M Excel Programming 5 June 27th 08 10:45 PM
Passing array from Access to Excel function Dale[_15_] Excel Programming 5 September 29th 05 07:30 PM
Passing an array as argument for custom Function No Name Excel Programming 4 March 7th 05 04:44 PM
Passing array of strings from DLL function to VBA Jag Man Excel Programming 0 January 12th 04 10:09 PM
Passing array to a function GB[_3_] Excel Programming 3 October 21st 03 09:59 AM


All times are GMT +1. The time now is 02:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"