How to pass an array to a procedure?

Kifsif

New Member
Joined
Mar 17, 2011
Messages
2
I can't pass an array to a procedure.

A B C
1 Name Zip Address
2 XYZ Telephone Inc. 567 1234 First Street

On the userform1 I have only one button.

My code.

Sub Archive()
Dim stickers(3) As String
stickers(1) = Cells(2, 1).Value
stickers(2) = Cells(2, 2).Value
stickers(3) = Cells(2, 3).Value
MsgBox (stickers(1) & Chr(10) & stickers(2) & Chr(10) & stickers(3))
UserForm1.Show
End Sub

Sub Spread(stickers())
Sheets(2).Select
Cells(2, 1).Value = stickers(1)
Cells(2, 2).Value = stickers(2)
Cells(2, 3).Value = stickers(3)
End Sub

Sub Archive()
Dim stickers(3) As String
stickers(1) = Cells(2, 1).Value
stickers(2) = Cells(2, 2).Value
stickers(3) = Cells(2, 3).Value
MsgBox (stickers(1) & Chr(10) & stickers(2) & Chr(10) & stickers(3))
UserForm1.Show
End Sub

Sub Spread(stickers())
Sheets(2).Select
Cells(2, 1).Value = stickers(1)
Cells(2, 2).Value = stickers(2)
Cells(2, 3).Value = stickers(3)
End Sub


Private Sub CommandButton1_Click()
Call Spread(stickers())
End Sub


So, the question. How can I call the sub Spread?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Welcome to MrExcel.

You need to declare stickers as Public at the top of the module so that it is visible to other procedures/modules. Be sure to remove the declaration from your Archive procedure.
 
Upvote 0
Public stickers(3) As String
Sub Archive()
stickers(1) = Cells(2, 1).Value
stickers(2) = Cells(2, 2).Value
stickers(3) = Cells(2, 3).Value

MsgBox (stickers(1) & Chr(10) & stickers(2) & Chr(10) & stickers(3))

UserForm1.Show

End Sub


Sub Spread(stickers())
Sheets(2).Select
Cells(2, 1).Value = stickers(1)
Cells(2, 2).Value = stickers(2)
Cells(2, 3).Value = stickers(3)

End Sub



Will yo be so kind as to help me elaborate the private sub code?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top