我正在尝试创建一个宏以滑动目录名称,然后创建一个过滤器。目录名称位于一列中,我想拆分姓氏。
示例:
sys-72285619869091378116913905
我想拿proyecgmailyou
从
C:\User\Kiyoshi\Documents\011.201-2016-CTE-AditivoDeConvenio-01-R00-FFF.docx
C:\User\Kiyoshi\Documents\011.201-2016-CTE-Monitoramento-01-R00-FFF.pdf
然后将其拆分为多个单元格
011.201-2016-CTE-AditivoDeConvenio-01-R00-FFF.docx
然后创建一个过滤器
答案 0 :(得分:0)
谢谢@mkyoshi给我一个值得挑战的挑战。尽管可能有其他方法可以实现您的目标,但以下是我的解决方案,该解决方案将子字符串立即填充到所选单元格右侧的列中。要使用宏,请选择包含字符串的单元格,然后执行宏。
import timeit
import numpy as np
from multiprocessing.pool import Pool
from scipy import spatial
# cKDTree implementation
def ckdTree():
tree = spatial.cKDTree(targets, leafsize=50)
return [tree.query(point, k=4) for point in sources]
# Initialization to transfer kdtree
def setKdTree(tree):
global kdtree
kdtree = tree
# Worker must not be in another function for multiprocessing
def multiprocKd_worker(point):
return kdtree.query(point, k=4)
# cKDTree process pool implementation
def multiprocCKd():
tree = spatial.cKDTree(targets, leafsize=50)
pool = Pool(initializer=setKdTree, initargs=(tree,))
return pool.map(multiprocKd_worker, sources)
if __name__ == "__main__":
# define the number of points for the two arrays
n_targets = 40000
n_sources = 40000
#pick some random points
targets = np.random.rand(n_targets, 3) * 100
sources = np.random.rand(n_sources, 3) * 100
print('cKDTree: %s' % timeit.Timer(lambda: ckdTree()).repeat(1, 1)[0])
print('multiprocCKd: %s' % timeit.Timer(lambda: multiprocCKd()).repeat(1, 1)[0])
由于该代码已被大量注释,我希望它是不言自明的。
答案 1 :(得分:0)
尽管如此,@ Scott Craner在他的评论(并要求将其作为答案供将来的SO读者使用 )中让我不知所措。 strong>认为这是最可接受的答案,我只是发布我认为是简单的VBA(经过测试)的解决方案之一(如果仅寻求VBA解决方案)。
Sub Breakup()
Dim Arr1 As Variant, Arr2 As Variant, Txt As String, Txt2 As String
Dim Rw As Long, StartRow As Long, LastRow As Long, ColStr As String
Dim Ws As Worksheet
Set Ws = ThisWorkbook.ActiveSheet 'May change to reqirement
'May use StartRow, lastrow as per requirement
ColStr = "B" ' column containing Path
StartRow = 2
'LastRow = 7
LastRow = Ws.Range(ColStr & Rows.Count).End(xlUp).Row
For Rw = StartRow To LastRow
Txt = Ws.Range(ColStr & Rw).Value
Arr1 = Split(Txt, "\")
If UBound(Arr1) >= -1 Then
Txt2 = Arr1(UBound(Arr1)) 'Last (filename) part of the split
Ws.Range(ColStr & Rw).Offset(0, 1).Value = Txt2
Arr2 = Split(Txt2, "-") 'Split file name with "-"
If UBound(Arr2) >= -1 Then
For Col = 0 To UBound(Arr2)
If Col = UBound(Arr2) Then 'To keep out extension part
Ws.Range(ColStr & Rw).Offset(0, Col + 2).Value = Split(Arr2(Col), ".")(0)
Else
Ws.Range(ColStr & Rw).Offset(0, Col + 2).Value = Arr2(Col)
End If
Next
End If
End If
Next
End Sub