New array equal old array

mc136355

New Member
Joined
Mar 20, 2018
Messages
36
hi guys
have the following code that works until i try to use the new array in a different routine.
when i do a MsgBox Join(newArr, ", ") in new sub the it returns an empty message box yet works fine in this sub

grateful on any solutions to this prob

thanks
MC

Dim result As String
Dim resultsFinal() As String
ReDim resultsFinal(0)
Dim i As Integer
Dim newArr As Variant


i = 0


result = 0


Dim wsf As Worksheet

For Each wsf In Sheets
If wsf.Name Like myArr & "*" Then

result = result + 1
ReDim Preserve resultsFinal(result)
resultsFinal(i) = wsf.Name
i = i + 1

End If
Next wsf

newArr = resultsFinal
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
.. i try to use the new array in a different routine.
Perhaps you could tell us more about how you are doing that - or better show us all the relevant code.

Also, in the code you posted, you have a variable myArr but it is not declared anywhere not does it have a value set. More information about that might be helpful too.
 
Upvote 0
Hi thanks for reply

my full code is as follows

Function Find_Sheet(myArr As String) As Boolean


Dim result As String
Dim resultsFinal() As String
ReDim resultsFinal(0)
Dim i As Integer




i = 0


result = 0


Dim wsf As Worksheet

For Each wsf In Sheets
If wsf.Name Like myArr & "*" Then

result = result + 1
ReDim Preserve resultsFinal(result)
resultsFinal(i) = wsf.Name
i = i + 1

End If
Next wsf

newArr = resultsFinal

MsgBox Join(newArr, ", ")
Var = Show_Records(myArr) '------


End Function





Function Show_Records(newArr As String) As Boolean




'Dim resultsFinal As String





MsgBox Join(newArr, ", ")


end function





thanks in advance
 
Upvote 0
I think you are confusing your variable names and types. In the first function myArr is a String and newArr is an array.
You are then passing the string myArr to the second function where it becomes the string newArr
In the second function your are trying to use Join on the string newArr but Join is a function for joining strings held in an array.

That is, you never passed the array newArr from the first function to the second.

Very mixed up! :)

Function Find_Sheet(myArr As String) As Boolean

newArr = resultsFinal

MsgBox Join(newArr, ", ")
Var = Show_Records(myArr) '------


End Function


Function Show_Records(newArr As String) As Boolean

MsgBox Join(newArr, ", ")

end function
 
Last edited:
Upvote 0
Hi

what i am attempting is to put list of all worksheets into an array begining only with certain text. Then work on that second array which will be smaller than the original. I'm new to vba and will persevere happily. thanks
MC
 
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...ch-array-and-put-results-in-second-array.html

Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
There's no need to delete the thread.
All we ask is that, in future, you supply links to any other sites where you have asked the same question.
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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