Turn Excel range into VBA string

前端 未结 7 1816
野性不改
野性不改 2020-11-30 11:51

I would like to turn values in given range into VBA string where original cell values are separated by any chosen column delimiter and row delimiter. Delimiters could be one

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 12:22

    Here's a quick way to test (Note: this will only work with Excel 2016 (or if you have the TextJoin() function).

    First, in the empty column D, do =C1&"@", so you get your last column filled with the cell+@

    Then, say in cell E1, =TEXTJOIN(",",TRUE,A1:C5) (Note: TRUE there means to skip blanks. If you have blanks, and want to keep them, change that to FALSE).

    THen, on that cell, run

    =Substitute(E1,"@,","@")

    Or combine the formulas into one: =SUBSTITUTE(TEXTJOIN(",",TRUE,A1:C4),"@,","@").

    If you need vba, just throw the formula into a VBA macro and run like that.

提交回复
热议问题