2016-06-02 12 views
0

文字列を変数として関数に渡そうとしましたが、配列の値を値と比較しようとすると、'424オブジェクトが必要'のエラーが発生します。与えられたセルで。私はVBAの初心者ですので、これは単純な構文エラーかもしれませんが、わかりません。ここに私のコードは次のとおりです。呼ばれてVBA Excelオブジェクトは、文字列配列変数を渡す必要があります

方法:

Sub InitializeCharts() 
    'Set's up the array for checking data names in the social groups 
    Dim socialArray As Variant 
    socialArray = Array("Chores", "Meat & Potatos", "Work", "Wind Down", "Reward") 
    '... 
    Call ChartLogic(Range("'ActivityTracker'!B12"), Range("'Groups'!F4"), socialArray) 
End Sub 

ChartLogic方法:事前に

Sub ChartLogic(dataCell As Range, tableCell As Range, socialArray As Variant) 
    Dim temp As Double 
    Dim count As Integer 

    '... 
    'Loops through the table and looks for the social cells with the same name, adding them to the chart 
    Do Until IsEmpty(dataCell) 
     For count = LBound(socialArray) To UBound(socialArray) 
      If socialArray(count).Value = dataCell.Value Then '<---Error Here 
       temp = socialCell.Offset(count, 0).Value 
       socialCell.Offset(count, 0).Value = temp + dataCell.Offset(0, 4).Value 
      End If 
     Next 
     Set dataCell = dataCell.Offset(1, 0) 
    Loop 
End Sub 

ありがとう! socialArray(count)プロパティValueを持つオブジェクトを生成しないので、

+0

一度あなたがそれを指摘したら明らかになりそうです! – newguy

答えて

1

Andrewが指摘しているように、socialArray(count).Value =は変種であるためエラーになります。このようなローカル変数として格納することができます。

ArrVal = socialArray(カウント)

For count = LBound(socialArray) To UBound(socialArray) 
    ArrayVal = socialArray(count) 
    If ArrayVal = dataCell.Value Then '<---Error Here 
     temp = socialCell.Offset(count, 0).Value 
     socialCell.Offset(count, 0).Value = temp + dataCell.Offset(0, 4).Value 
    End If 
Next 

それともセルではありませんし、ワークシートオブジェクトが、バリアントではないとして、あなただけの.VALUEをオフに取ることができます。

あなたはこの `もしsocialArray(回数).Valueの= dataCell.Value次に`この `socialArrayは(カウント)した場合= dataCell.Value次に`迅速な返信用
+0

これは完璧な意味合いです。一度それを指摘すれば、本当に明白です。助けてくれてありがとう! – Alex

3

あなたはオブジェクトを取得しているがエラーが必要。言い換えれば

socialArrayが文字列のArrayであることから、socialArray(count)はすでにValueの必要はないのです - そこに文字列を生成します。

+0

おかげで、これを変更する必要があります下に答えたよう

If socialArray(count) = dataCell.Value Then 
Alex

関連する問題