ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing array elements to a function (https://www.excelbanter.com/excel-programming/411455-passing-array-elements-function.html)

Geoff

Passing array elements to a function
 
Hi
Passing the contents of the array element to the function works, the
function does its job but returns "" to the array.
It has to be something simple that I'm missing but it escapes me for now.
Any help would be appreciated.

Geoff

Dim j As Long, realLastRow as Long
Dim tbl2 As Variant

tbl2 = Range(Cells(2, "A"), Cells(realLastRow, "A"))
For j = LBound(tbl2, 1) To UBound(tbl2, 1)
tbl2(j, 1) = GetNum(tbl2(j, 1))
Next j
Range(Cells(2, "A"), Cells(realLastRow, "A")) = tbl2

Public Function GetNum(num As Variant) As String
'''do something
num = "01234567"
End Function


Gary''s Student

Passing array elements to a function
 
You need to pass it back thru the name:

Public Function GetNum(num As Variant) As String
GetNum = "01234567"
End Function


--
Gary''s Student - gsnu200788


"Geoff" wrote:

Hi
Passing the contents of the array element to the function works, the
function does its job but returns "" to the array.
It has to be something simple that I'm missing but it escapes me for now.
Any help would be appreciated.

Geoff

Dim j As Long, realLastRow as Long
Dim tbl2 As Variant

tbl2 = Range(Cells(2, "A"), Cells(realLastRow, "A"))
For j = LBound(tbl2, 1) To UBound(tbl2, 1)
tbl2(j, 1) = GetNum(tbl2(j, 1))
Next j
Range(Cells(2, "A"), Cells(realLastRow, "A")) = tbl2

Public Function GetNum(num As Variant) As String
'''do something
num = "01234567"
End Function


Geoff

Passing array elements to a function
 
Hi
That was fine.

Thank you.

Geoff

"Gary''s Student" wrote:

You need to pass it back thru the name:

Public Function GetNum(num As Variant) As String
GetNum = "01234567"
End Function


--
Gary''s Student - gsnu200788


"Geoff" wrote:

Hi
Passing the contents of the array element to the function works, the
function does its job but returns "" to the array.
It has to be something simple that I'm missing but it escapes me for now.
Any help would be appreciated.

Geoff

Dim j As Long, realLastRow as Long
Dim tbl2 As Variant

tbl2 = Range(Cells(2, "A"), Cells(realLastRow, "A"))
For j = LBound(tbl2, 1) To UBound(tbl2, 1)
tbl2(j, 1) = GetNum(tbl2(j, 1))
Next j
Range(Cells(2, "A"), Cells(realLastRow, "A")) = tbl2

Public Function GetNum(num As Variant) As String
'''do something
num = "01234567"
End Function



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

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