Cannot assign to Array

u144644

New Member
Joined
Sep 20, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Help, I am getting the error "Cannot assign to Array" calling on function to return array with values.
See code below.

Sub Get_Values()

Dim Arr(1 To 5) As String
Dim Txt As String

Txt = "Some Text passed to Function"

Arr = Split_Words(Txt) '<--- Error "Cannot assign to Array"

End Sub

Function Split_Words(ByRef Txt As String) As String()

Dim Arr(1 To 5) As String

'Code

Split_Words = Arr

End Function
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about
VBA Code:
Sub Get_Values()

Dim Arr As Variant
Dim Txt As String

Txt = "Some Text passed to Function"

Arr = Split(Txt)

End Sub
 
Upvote 0
You can only assign to a dynamic array, so your declaration should be:

VBA Code:
Dim Arr() As String
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,258
Members
449,149
Latest member
mwdbActuary

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