ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   excel vba array basic operations (https://www.excelbanter.com/excel-programming/285393-excel-vba-array-basic-operations.html)

Gabriel[_3_]

excel vba array basic operations
 
Hello,

I just want to create my own function in vba that involve basic array
operations. I've already implemented them in an excel spreadsheet and
I thought it would be rather straightforward to create the functions
in vba.

For instance, I wanted to test a function that perfoms a difference
between two arrays (3;5) and (1;2). In a worksheet I just select the
next two cells, enter the formula and CTRL-Shift-Enter and voila
(2;3). But when I select the appropiate range and call the following
function, it just doesn't work.

Function diffArray(vector1, vector2) As Variant
diffArray = vector1 - vector2
End Function

Any hint?
Gabriel

Tom Ogilvy

excel vba array basic operations
 
You have to loop and do the comparison element for element, then store the
results in a third array.

There are no built in Array operations in VBA.

--
Regards,
Tom Ogilvy

Gabriel wrote in message
om...
Hello,

I just want to create my own function in vba that involve basic array
operations. I've already implemented them in an excel spreadsheet and
I thought it would be rather straightforward to create the functions
in vba.

For instance, I wanted to test a function that perfoms a difference
between two arrays (3;5) and (1;2). In a worksheet I just select the
next two cells, enter the formula and CTRL-Shift-Enter and voila
(2;3). But when I select the appropiate range and call the following
function, it just doesn't work.

Function diffArray(vector1, vector2) As Variant
diffArray = vector1 - vector2
End Function

Any hint?
Gabriel




Alan Beban[_4_]

excel vba array basic operations
 
You might want to review some of the functions in the freely
downloadable file at http://home.pacbell.net/beban. The following, for
example, will produce the result you are describing:

=ArrayAdd(vector1,vector2,false)

The loops are included in the function.

Alan Beban

Gabriel wrote:
Hello,

I just want to create my own function in vba that involve basic array
operations. I've already implemented them in an excel spreadsheet and
I thought it would be rather straightforward to create the functions
in vba.

For instance, I wanted to test a function that perfoms a difference
between two arrays (3;5) and (1;2). In a worksheet I just select the
next two cells, enter the formula and CTRL-Shift-Enter and voila
(2;3). But when I select the appropiate range and call the following
function, it just doesn't work.

Function diffArray(vector1, vector2) As Variant
diffArray = vector1 - vector2
End Function

Any hint?
Gabriel




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com