我有一张纸,里面装满了我想提取的文件。它们存在于A列:D列中,但散布在整个纸张中。中间还有其他文本的空白行。 (这是一堆代码)。有没有人有任何提取这些文件名的策略?逐行是繁琐的,过滤由于空白而不起作用,但是每个文件名都以" / home"通常
答案 0 :(得分:1)
正如here所述,您可以在循环中使用.Find
来迭代包含特定类型值的单元格:
Sub ExtractFileNames()
Application.ScreenUpdating = False
Dim R As Range, c As Range, copyTo As Range
Dim startCell As String
Set copyTo = Sheets(2).Range("A1")
Set R = Intersect(Sheets(1).UsedRange, Sheets(1).Range("A:D"))
Set c = R.Find("*/*.*")
If Not c Is Nothing Then
startCell = c.Address
Do
copyTo.Value = c.Value
Set copyTo = copyTo.Offset(1)
Set c = R.FindNext(c)
Loop Until c Is Nothing Or c.Address = startCell
End If
Application.ScreenUpdating = True
End Sub