我在下面的子行中有線tableauScores(i - 1, j).Value = wsScores.Cells(2 + i * 3, j + 1).Value
上的錯誤424'所需對象'。變體上所需的對象
只有這個子,沒有別的。我在基地0.
Dim wsScores As Worksheet
Dim i As Integer, j As Integer
Dim tableauScores As Variant
Set wsScores = ThisWorkbook.Worksheets("Scores")
j = 0
ReDim tableauScores(1, 2)
If wsScores.Cells(2, 1).Value = "Thomas" Then
For i = 1 To 2
For j = 1 To 3
tableauScores(i - 1, j).Value = wsScores.Cells(2 + i * 3, j + 1).Value
Next j
Next i
End If
End Sub
我不明白爲什麼,我總是使用這樣的變體。
你可以使用'使用ReDim tableauScores(1〜2個,1〜3)',使您更容易計算 –
[Variant數據類型(https://開頭MSDN。 microsoft.com/en-us/library/office/gg251448.aspx)本身沒有屬性「Value」。要將值分配給'Variant',您只需將其分配給變量本身。 – dee
@dee主要觀點不是'Variant'沒有'Value'屬性。下面的代碼將起作用:'Dim v As Variant:Set v = ActiveWorksheet.Cells(1,1):Debug.Print v.Value';即使變量'v'的類型是'Variant',它所引用的對象也具有'Value'屬性,並且VBA將在運行時解析該屬性。 –