Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Function (array argument, range argument, string argument) vba

Hi,

Long time .... ok no tears.

Problem:
I would like to write Function with many argument:
array, range, string, double etc,

Public newarray() as String

Function fillArray(varArray1() as Variant, _
optional select1 as Range, arg1 as Single)

dim i as single
for i=0 to 5000
newarray(i)=i+arg1
next i
end Function

I call this function with Sub Procedure
sub firstsub()
fillArray fillArray,
end sub
I'm siting many weeks and nothing, I read many FAQ,
but all post have only one (array) argument.
tx for help
Witek

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Function (array argument, range argument, string argument) vba

Not sure I understand, so I'll just throw this out. Are there any ideas
here that would help?

Option Explicit
Public NewArray() As String

Function FillArray(ParamArray v())
Dim n As Long
Dim p As Long

' How many elements?
n = UBound(v) - LBound(v) + 1
ReDim Preserve NewArray(1 To n)

'// Keep track of 1-Based vs. 0-Based Arrays
For p = 1 To n
NewArray(p) = v(p - 1)
Next p
End Function

Sub First_Sub()
FillArray "Cat", "Dog", 3.14, Sqr(2), "More_Text", "etc"
End Sub

--
Dana DeLouis
Win XP & Office 2003


<Witek wrote in message ...
Hi,

Long time .... ok no tears.

Problem:
I would like to write Function with many argument:
array, range, string, double etc,

Public newarray() as String

Function fillArray(varArray1() as Variant, _
optional select1 as Range, arg1 as Single)

dim i as single
for i=0 to 5000
newarray(i)=i+arg1
next i
end Function

I call this function with Sub Procedure
sub firstsub()
fillArray fillArray,
end sub
I'm siting many weeks and nothing, I read many FAQ,
but all post have only one (array) argument.
tx for help
Witek

*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Function (array argument, range argument, string argument) vba

:) thanku you Dana. It's really help. I have more difficult (for me
problem)

I would like write Function which fills Array (NewArray) from Selection,
Range etc. This Function take Public Array as argument (or name this
Array) and fill Array from Selection, rng1 or other Range (regular
Range). It will uniwersal Function for all my Arrays:)

Public NewArray() Ss String

Sub test()
fillArray(NewArray(), Cells(1,2), Selection, True)
End Sub

Public Function fillArray(varArray1() As String, Optional
CellsWihtSelection As Range, Optional Rng1 As Range, Optional isHead As
Boolean = True) As String()
If Not Rng1 Is Nothing then
varArray=rng1
Elseif
CellsWihtSelection.CurrentRegion.Select
varArray=Selection
End If
End Function

When it is not posible, how take name of array as string? I think it's
stupied why to solve this problem, but I try

Public newarray() as String

Function fillArray(varArray1() as Variant, _
Optional select1 as Range, Optional arg1 as Single)

Dim i as Single
for i=0 to 5000
newarray(i)=i+arg1
next i
End Function

I call this function with Sub Procedure
sub First_Sub()
fillArray fillArray(), Selection,
end sub




*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Function (array argument, range argument, string argument) vba

Most of you problem has to do with syntax errors and not mistyping. this
worked fine for me in Excel 97


Option Explicit
Public NewArray As Variant

Sub test()
Dim i As Long, j As Long
fillArray NewArray, Cells(1, 2), Selection, True
For i = LBound(NewArray, 1) To UBound(NewArray, 1)
For j = LBound(NewArray, 2) To UBound(NewArray, 2)
Debug.Print i, j, NewArray(i, j)
Next
Next
End Sub

Public Function fillArray(varArray1 As Variant, _
Optional CellsWithSelection As Range, _
Optional Rng1 As Range, _
Optional isHead As Boolean = True)
If Not Rng1 Is Nothing Then
If Rng1.Count = 1 Then
ReDim varArray1(1 To 1, 1 To 1)
varArray1(1, 1) = Rng1.Value
Else
varArray1 = Rng1.Value
End If
Else
If Not CellsWithSelection Is Nothing Then
CellsWithSelection.CurrentRegion.Select
If Selection.Count = 1 Then
ReDim varArray1(1 To 1, 1 To 1)
varArray1(1, 1) = Selection.Value
Else
varArray1 = Selection
End If
End If
End If
End Function

--
Regards,
Tom Ogilvy

<Witek wrote in message ...
:) thanku you Dana. It's really help. I have more difficult (for me
problem)

I would like write Function which fills Array (NewArray) from Selection,
Range etc. This Function take Public Array as argument (or name this
Array) and fill Array from Selection, rng1 or other Range (regular
Range). It will uniwersal Function for all my Arrays:)

Public NewArray() Ss String

Sub test()
fillArray(NewArray(), Cells(1,2), Selection, True)
End Sub

Public Function fillArray(varArray1() As String, Optional
CellsWihtSelection As Range, Optional Rng1 As Range, Optional isHead As
Boolean = True) As String()
If Not Rng1 Is Nothing then
varArray=rng1
Elseif
CellsWihtSelection.CurrentRegion.Select
varArray=Selection
End If
End Function

When it is not posible, how take name of array as string? I think it's
stupied why to solve this problem, but I try

Public newarray() as String

Function fillArray(varArray1() as Variant, _
Optional select1 as Range, Optional arg1 as Single)

Dim i as Single
for i=0 to 5000
newarray(i)=i+arg1
next i
End Function

I call this function with Sub Procedure
sub First_Sub()
fillArray fillArray(), Selection,
end sub




*** Sent via Developersdex http://www.developersdex.com ***



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
VBA function for "Mean" using Array as argument ASokolik Excel Worksheet Functions 21 March 28th 06 10:05 PM
Passing an array as argument for custom Function No Name Excel Programming 4 March 7th 05 04:44 PM
Passing a string aray as an argument to a function ?....Help! Dan Thompson Excel Programming 5 September 29th 04 03:01 AM
Range as argument in function Asif[_3_] Excel Programming 3 December 6th 03 01:38 PM
Passing an Array of User-Defined Type to an Argument of a Function Tushar Mehta[_6_] Excel Programming 0 August 17th 03 06:43 PM


All times are GMT +1. The time now is 11:28 AM.

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

About Us

"It's about Microsoft Excel"