此函數獲取兩個參數一個範圍和一個值以匹配內部範圍,然後返回一個數組與匹配值和他們的地址。但它給出了ReDim Preserve
錯誤,也當數組是空的(不匹配任何值)提示錯誤ReDim保留二維超出範圍
Function filter_range_value(rng As String, selected_value As String) As Variant
Dim cell As Range
Dim array_storage() As Variant
Dim element As Integer
element = 1
For Each cell In Range(rng)
If InStr(cell, selected_value) > 0 Then
ReDim Preserve array_storage(element, 1)
array_storage(element, 0) = cell
array_storage(element, 1) = cell.address
element = element + 1
End If
Next cell
filter_range_value = array_storage
End Function
你嘗試'REDIM保留array_storage(0至元素,0〜1)'? –
您只能重新保留最後一個維度。在2D中,它是第二個,第三個,第三個,.... –