2

我有一个脚本,可以很好地根据两列创建文件夹,但由于某种原因,它的末尾有一个空格的文件夹。

这是代码:

Dim baseFolder As String, newFolder As String
    lastrow = wsJL.Cells(Rows.Count, "B").End(xlUp).Row
    wsJL.Range("S2:U2").Copy wsJL.Range("S3:U" & lastrow)
    Range("J3:M" & lastrow).Calculate
    Range("S3:U" & lastrow).Calculate
    baseFolder = wbBK1.path & Application.PathSeparator & "Photos" & Application.PathSeparator
     'folders will be created within this folder - Change to sheet of your like.

    If Right(baseFolder, 1) <> Application.PathSeparator Then _
     baseFolder = baseFolder & Application.PathSeparator

       For Each cell In Range("S3:S" & lastrow)   'CHANGE TO SUIT

           'Company folder - column S

           newFolder = baseFolder & cell.Value
           If Len(Dir(newFolder, vbDirectory)) = 0 Then MkDir newFolder

           'Part number subfolder - column T

           newFolder = newFolder & Application.PathSeparator & cell.Offset(0, 1).Value
           If Len(Dir(newFolder, vbDirectory)) = 0 Then MkDir newFolder

       Next

        End With

现在它被赶上的是这个:

"The Richmond Group "我认为的原因是因为它在标题末尾有一个空格,并且在创建文件夹时不会转换为空格。

现在我在 S 和 T 中是这样的:

小号

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($C2,",","")," "," "),".",""),"/","-"),"""",""),"*","")

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($D2,",","")," "," "),".",""),"/","-"),"""",""),"*","")

话虽如此,我想不出一种方法来删除名称末尾的结尾空格。

如果有人可以在那里提供帮助,将不胜感激。

4

2 回答 2

3

尝试修剪功能:

将 LResult 调暗为字符串

LResult = 修剪(“字母”)

http://www.techonthenet.com/excel/formulas/trim.php

于 2012-09-28T12:15:17.973 回答
3

使用Trim$.

它是一个字符串函数,这意味着它比它的变体表亲更有效Trim

一个非常有用的参考请不要变种

于 2012-09-28T12:25:33.740 回答