Retrieve an array from a function?

  • Thread starter Thread starter PK
  • Start date Start date
P

PK

Help please!

I am using VBA in Excel XP with Windows 2000.

I am fairly experienced using VBA, but I recently began
using functions. Is it possible to return an array from a
function?

For example, the following function call retrieves a month
and a year from drop downs in a toolbar. The actual
function gets the information, but how do I retrieve this
info from the function to my subroutine in a separate
module?

Call Obtain_Period("Bank_Month", "Bank_Year")

Thanks inadvance for the lesson. Your example code would
be most appreciated.
 
You don't need a function

Sub DoingTheCalling()
dim lngMonth as Long
Dim lngYear as Long
Call Obtain_Period(lngMonth, lngYear)
msgbox "Month: " & lngMonth & " Year: " & lngYear
End Sub

Sub Obtain_Period(lMonth as Long, lYear as Long)
Dim ctlMonthComboBox As CommandBarComboBox
Dim ctlYearComboBox As CommandBarComboBox
Dim cBar as Commandbar
set cBar = CommandBars("Custom1")
set ctlMonthCombobox = cbar.Controls("MonthDropDown")
set ctlYearCombobox = cbar.Controls("YearDropDown")
lMonth = clng(ctlMonthCombobox.Text)
lYear = clng(ctlYearCombobox.Text)
End Sub

If your Month combobox is producing strings, then change the code to address
a string.
 
Back
Top