我尝试编写一个返回数组的属性。属性在工作表的第一行(输入参数2)中搜索字符串(在属性VarGropu中设置)。找到该字符串后,它会在其列中查找第一个空单元格,并将第3行中的每个值复制到第一个空单元格中并返回它。它应该如何,但它不起作用,我不知道为什么。
Private myVarGroup As String
Public Property Get VarGroup() As String
VarGroup = myVarGroup
End Property
Public Property Let VarGroup(Value As String)
myVarGroup = Value
End Property
Public Property Get SelectCodes(ByRef CodeWs As Worksheet, ByVal CodeHeaderRow As Integer) As String()
Dim LangColumn As Integer
LangColumn = CodeWs.Range(Cells(CodeHeaderRow, 1), Cells(CodeHeaderRow, 250)).Find(myVarGroup).Column
Dim lastRow As Long
lastRow = CodeWs.Columns(LangColumn).Find("*", , , , xlByColumns, xlPrevious).Row - 2
Dim ArrayCodes() As String
ReDim ArrayCodes(1 To lastRow)
Dim i As Integer
For i = 1 To lastRow - 2
ArrayCodes(i) = CodeWs.Cells(i + 2, LangColumn)
Next i
Set SelectCodes = ArrayCodes
End Property
Stackoverflow上有两个类似的问题,但它们对我没有帮助。如果有人能帮助我的话,那会很棒!