ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing Arrays to a Sub (https://www.excelbanter.com/excel-programming/425369-passing-arrays-sub.html)

Brad

Passing Arrays to a Sub
 
I have an array of strings (sIssue) made up of different strings concatanated
together. The way sIssue will be constructed will be used repeatedly in my
program so what I would like to do is write a subroutine to construct this
array for the main program. I'm just not sure how to do this. I would like
for the code to work something like below

Sub Main()

' Do stuff
dim sIssue (1 to 8) as string

GetString(sIssue())

Range("B1").Select
for i = 1 to 8
ActiveCell.Offset(i,0).Value = sIssue(i)
next

End
-----------------
sub GetString(Byval sIssue as string)

' do stuff
for i = 1 to 8
sIssue(i) = ActiveCell.Offset(i,0) & ActiveCell.Offset(i,2)
next
End

Thanks in advance

end sub



Bob Phillips[_3_]

Passing Arrays to a Sub
 
Sub Main()
' Do stuff
dim sIssue As Variant
sIssue = GetString()

For i = 1 to 8
Cells(i,"B").Value = sIssue(i)
Next
End Sub

Private Function GetString() As Variant
' do stuff
for i = 1 to 8
GetString(i) = ActiveCell.Offset(i,0) & ActiveCell.Offset(i,2)
Next
End Function



--
__________________________________
HTH

Bob

"Brad" wrote in message
...
I have an array of strings (sIssue) made up of different strings
concatanated
together. The way sIssue will be constructed will be used repeatedly in my
program so what I would like to do is write a subroutine to construct this
array for the main program. I'm just not sure how to do this. I would like
for the code to work something like below

Sub Main()

' Do stuff
dim sIssue (1 to 8) as string

GetString(sIssue())

Range("B1").Select
for i = 1 to 8
ActiveCell.Offset(i,0).Value = sIssue(i)
next

End
-----------------
sub GetString(Byval sIssue as string)

' do stuff
for i = 1 to 8
sIssue(i) = ActiveCell.Offset(i,0) & ActiveCell.Offset(i,2)
next
End

Thanks in advance

end sub






All times are GMT +1. The time now is 01:38 AM.

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