View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
[email protected] wkwells@bellsouth.net is offline
external usenet poster
 
Posts: 6
Default Call a function within Excel VBA --- need help can't figure out syntax correctly

Thats exactly what I am trying to do

I have a Workbook with maybe 40 sheets, the first sheet in the
Workbook has a list of the worksheets, I have named this Range
MySheets. I want to sort the SHEET TABS in the same order as this
Range.

Sub TestArray()
NameArray = Range("MySheets").Value
'Looping structure to look at array.
For i = 1 To UBound(NameArray)
MsgBox NameArray(i, 1)
Next
End Sub

I know this works to create the Array

My Problem is transferring this Array Information to the
SortWorksheetsByNameArray Function

Appreciate the help

On Wed, 01 Feb 2012 13:41:05 -0500, GS wrote:

Thanks for posting back!
There's good reasons for an error being raised...

Firstly, your call is missing args needed by the function. It takes 3
args, the first 2 of those are compulsory while the 3rd is optional.

Secondly, the array being passed to the function needs to be 1D. You
are trying to pass a 2D array. You need to put the list into a temp
array BEFORE passing it to the function.
--

As for the function structure itself, IMO it seems a bit
'long-in-tooth' for the task at hand. I'd certainly want to revise this
to something more efficient for the task. If all you're doing is
reordering specific sheets to be adjacent to each other as per the same
order they appear in NameArray, only one loop is necessary to
accomplish this (even if the first sheet in the list stays put and the
remaining sheets stack up beside it). Do you mind telling me where you
got this function? (It's 'style' looks vaguely familiar)

I'll try to come up with something that will work better for you in
your scenario, and post back...