下面的代码将一系列单元格连接成一个字符串,相信这将归功于我之前post的JNevill。
我一直在redim区域遇到类型不匹配错误。我还尝试在减去1之前将其包裹在Ubound周围,但这仍然给我一个类型不匹配错误。
Function convertRangetoList(myRange As Range, delimiter As String) As String
Dim rngCell As Range
Dim arrNames() As Variant
Dim i As Long
'redim the array
ReDim arrNames(myRange - 1)
'Load the array
i = 0
For Each rngCell In myRange
arrNames(i) = rngCell.Value
i = i + 1
Next
' Join to comma seperate array
convertRangetoList = Join(arrNames, delimiter)
End Function
答案 0 :(得分:1)
Redim
期待Number不是Range对象。使用Range.CountLarge
返回范围内所有区域中所有单元格的总数。
ReDim arrNames(myRange.CountLarge - 1)