Array functions inVB code

Savanur

New Member
Joined
Aug 12, 2002
Messages
15
Hi all,

How to use Array functions in VB code. We use Worksheetfunction.xlfunction to access xl functions.

But how about array functons..?

Thanks in advance.

Savanur
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I use DAO 3.6.

In the VB editor, go to Tools|References, and uncheck the ActiveX 2.1 library reference and add Microsoft DAO 3.6.

Now in code, you can do something like this:
Code:
Dim db As Database
Dim rs As Recordset
Dim selSQL As String
Dim myArray() As Variant
Dim recCount As Integer, i As Integer

    Set db = CurrentDb()
    
    'enter the sql to generate what's going into the array
    'adjust to suit
    selSQL = "SELECT [myTable].* FROM [myTable];"
    
    Set rs = db.OpenRecordset(selSQL)
    rs.MoveLast
    recCount = rs.RecordCount
    
    'size the array
    ReDim myArray(1 To recCount)
    rs.MoveFirst
    
    'stack the array, adjust myField to suit
    For i = 1 To recCount
        myArray(i) = rs!myField
        rs.MoveNext
    Next i

This will fill an array up with all the data from myField in myTable.
 
Upvote 0
I think he may mean "how do you setup a function/subroutine to receive a variable number of values"

If yes, you use this as your Function/Sub line:

Code:
Public Sub subName(ParamArray strVal() As Variant)

You must use a Variant array to do this.
I believe you can specify other variables to be passed to the function, but the last on the list must be the Parameter Array.

Mike
 
Upvote 0

Forum statistics

Threads
1,221,618
Messages
6,160,873
Members
451,674
Latest member
TJPsmt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top