VBA - Set Array Equal to Array

Dsewardj

Board Regular
Joined
Dec 30, 2008
Messages
155
I am trying to determine values in one array and pass them into another array. Below is my code:

Code:
'Print selected teams to Metrics-Site worksheet
Dim teamTfArray() As Variant
Dim prntTeamArray() As Variant
Dim x, j, z
j = 0
z = Sheets("Valid Values").Range("cbTeamTotal").Value
ReDim prntTeamArray(1 To z)
teamTfArray() = Sheets("Valid Values").Range("TeamTF").Value
For Each x In teamTfArray()
    If x = "" Then
    Else
    j = 1 + j
    prntTeamArray(j) = teamTfArray(x)
    End If
Next x

What I'm trying to do is find any text value in teamTfArray that doesn't equal "" and pass it into an element in prntTeamArray. It gives me a MisMatch error and I'm not sure why?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Well I answered part of my question. I changed my code to this below:

Code:
'Print selected teams to Metrics-Site worksheet
Dim teamTfArray() As Variant
Dim prntTeamArray() As Variant
Dim x, j, z
j = 0
z = Sheets("Valid Values").Range("cbTeamTotal").Value
ReDim prntTeamArray(1 To z)
teamTfArray() = Sheets("Valid Values").Range("TeamTF").Value
For Each x In teamTfArray()
    If x = "" Then
    Else
    j = 1 + j
    prntTeamArray(j) = x
    End If
Next x

x is an element in teamTfArray, so there was no need to include it in prntTeamArray(j) = teamTfArray(x).

Now a Subscript Out of Range error is occurring with the prntTeamArray(j) statement. I'm not sure why this is occurring.
 
Upvote 0

Forum statistics

Threads
1,224,096
Messages
6,176,325
Members
452,721
Latest member
Du Toit

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