Is it possible to fill an array with row numbers which match a certain criteria without looping?

前端 未结 8 1834
陌清茗
陌清茗 2020-11-27 17:33

I would like to fill an array in VBA with the row numbers of only rows which meet a certain criteria. I would like the fastest method possible (for example, something like <

8条回答
  •  孤独总比滥情好
    2020-11-27 18:22

    Everyone, thanks for your individual inputs.

    ExactaBox, your solution has been much helpful to me. However, there is a catch in returning 0 value through formula

    rFormula.FormulaR1C1= "=IF(RC[-1]=""" & valMatch & """,ROW(RC),0)".

    Since VBA Filter function filters out values by making string comparisons, it would also filter out row numbers having zeroes in them. For example valid row numbers, 20, 30, 40 etc. shall also be filtered out because they contain zeroes, so it would be better to write a string in place of 0 in the formula, which could therefore be:

    rFormula.FormulaR1C1= "=IF(RC[-1]=""" & valMatch & """,ROW(RC),""Valid"")"

    as was also suggested by brettdj above, who used "x" string as the last argument.

提交回复
热议问题