Excel公式用空格替换剩余的字符

时间:2017-11-16 07:17:58

标签: excel vba excel-vba

我正在尝试连接表1或表2中所有列或每一行的值,但是在表1中的每一列中都有一个分配的字符,因此无论是空白还是未完全填充它都会消耗相同的数量输出表中的空格。

  

我想要的输出示例:

     

表1(输入)

     

每列分配的字符:身份证号码(4),余额(7),或号码(5),帐户名称(10),参考代码(5)

     

| ---身份证号码--- | ---余额--- | ---或号码--- | ---账户名称--- | ---参考码--- |

     

| ------- 003 ------- | - 5,000,000 - | ------ 12345 ------ | ----运输----- | - -------- 11123 ---------- |

     

| ------- 010 ------ | ---- 5,000 ---- | ------ 31234 ------ | -----人类A ------ | ----------- 121 ----------- |

     

| ------- 33 -------- | -------- -------- | ------ 56567 ----- - | ------测试-------- | ----------- 54321 -------- |

     

| ------- 111 ------ | ------- 7 ------- | ------------ --- ------- | -----人类B ------ | ----------- 21 ------------ |

Sheet 2 (Output) 

003500000012345Transports11123
010   500031234   Human A  121 
 33       56567   Testing54321
111      7        Human B   21 

如果单元格为空,我当前的公式只留下空格,我不知道是否有excel代码用空白字符替换剩余空格。

=IF(A10="","",
IF(LEFT(A10,1)="T","",
IF(Input!A11<>"",
IF(Input!A11=""," ",Input!A11)&
IF(Input!B11="","   Input! ",Input!B11)&
IF(Input!C11="","      ",Input!C11)&
IF(Input!D11="","      ",Input!D11)&
IF(Input!E11="","      ",Input!E11)&
IF(Input!F11="","      ",Input!F11)&
IF(Input!G11="","            ",Input!G11)&
IF(Input!H11="","          ",Input!H11)&
IF(Input!I11="","          ",Input!I11)&
IF(Input!J11="","      ",Input!J11)&
IF(Input!K11="","          ",Input!K11)&
IF(Input!L11="","                              ",Input!L11)&
IF(Input!M11="","      ",Input!M11)&
IF(Input!N11="","          ",Input!N11)&
IF(Input!O11="","   ",Input!O11)&
IF(Input!P11="","   ",Input!P11)&
IF(Input!Q11="","          ",Input!Q11)&
IF(Input!R11="","            ",Input!R11)&
IF(Input!S11="","         ",Input!S11),"T"&MIN(ROW(A11:A12))+ROWS(A11)-3&"   "&SUM(Input!H:H))))

0 个答案:

没有答案