Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA passing vector from spreadsheet to array

Hi all,


What is the proper way (best way) how to pass date vector fro
spreadsheet to a date vector inside VBA?


Ideally I would like to have something like this:



Code
-------------------

Public Function foo(inputVector() As Date)

Dim firstDate As Date
firstDate=inputVector(1)

...

End Function

-------------------



but this does not work.

Thanks

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA passing vector from spreadsheet to array

I think that you need to pass the array and then process that for dates.

This is an example of handling an array

Function test(a)
Dim i As Long
Dim maxVal
For i = LBound(a, 1) To UBound(a, 1)
If a(i) maxVal Then
maxVal = a(i)
End If
Next i
test = maxVal
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"curious " wrote in message
...
Hi all,


What is the proper way (best way) how to pass date vector from
spreadsheet to a date vector inside VBA?


Ideally I would like to have something like this:



Code:
--------------------

Public Function foo(inputVector() As Date)

Dim firstDate As Date
firstDate=inputVector(1)

...

End Function

--------------------



but this does not work.

Thanks,


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA passing vector from spreadsheet to array

Sub Main()
dim arrDate(1 to 10) as Date
i = 0
for each cell in Range("A1:A10)
i = i + 1
arrDate(i) = Cell.Value
Next
Foo arrDate

End Sub

If you want to put values from a worksheet into other than a variant, you
have to do it a cell at a time.

--
Regards,
Tom Ogilvy


"curious " wrote in message
...
Hi all,


What is the proper way (best way) how to pass date vector from
spreadsheet to a date vector inside VBA?


Ideally I would like to have something like this:



Code:
--------------------

Public Function foo(inputVector() As Date)

Dim firstDate As Date
firstDate=inputVector(1)

...

End Function

--------------------



but this does not work.

Thanks,


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default VBA passing vector from spreadsheet to array

If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook, doing it a
cell at a time is built in to the Assign function:

Sub Main()
Dim arrDate() As Date
Assign MakeArray(Range("A1:J1"),1), arrDate
End Sub

The MakeArray function converts the input to a 1-dimensional array. If
the input is single-column range, the following also works:

Sub Main()
Dim arrDate() As Date
Assign Application.Transpose(Range("A1:A10")), arrDate
End Sub

Alan Beban

Tom Ogilvy wrote:

Sub Main()
dim arrDate(1 to 10) as Date
i = 0
for each cell in Range("A1:A10)
i = i + 1
arrDate(i) = Cell.Value
Next
Foo arrDate

End Sub

If you want to put values from a worksheet into other than a variant, you
have to do it a cell at a time.

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
Please add an INTERPOLATE function. For vector or array data. Dan Gauthier Excel Worksheet Functions 15 August 4th 09 01:48 PM
Lookup that returns vector(array) BOB77 Excel Discussion (Misc queries) 3 March 25th 08 07:50 PM
How do I draw 3D vector arithmetic, showing vector subtraction? Colin Kemp Excel Discussion (Misc queries) 0 April 5th 06 07:30 AM
The # in my vector is absent from my array. Can I make it 0? Matherley Excel Worksheet Functions 1 July 14th 05 08:52 PM
PASSING an array to a sub in VBA Wombat[_2_] Excel Programming 2 November 30th 03 11:48 AM


All times are GMT +1. The time now is 05:04 PM.

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

About Us

"It's about Microsoft Excel"