excel - ReDim Preserve results in mistake -
i have function takes range of cells argument , checks how many of these cells contain '2' or '3', gives message box determined text. problem dynamic array. if use array of fixed length, works fine. once employed redim preserve method, function doesn't return value in cell , doesn't display message box... what's wrong here?
function test2(var range) dim result0 integer dim resultsfinal() long redim resultsfinal(0) dim integer = 0 result = 0 dim cell range each cell in var.cells if cell.value = 2 or cell.value = 3 result = result + 1 redim preserve resultsfinal(result) resultsfinal(i) = cell.row = + 1 test2 = cell.value end if next cell msgbox result & "and " & vbnewline & array: " & join(resultsfinal, ", ") end function
the join command works strings or variant.
if change string , fix couple of typos works fine
function test2(var range) dim result integer dim resultsfinal() string redim resultsfinal(0) dim integer = 0 result = 0 dim cell range each cell in var.cells if cell.value = 2 or cell.value = 3 result = result + 1 redim preserve resultsfinal(result) resultsfinal(i) = cell.row = + 1 test2 = cell.value end if next cell msgbox result & "and " & vbnewline & " array: " & join(resultsfinal, ", ") end function
Comments
Post a Comment