VBA:在单元格中搜索mm的书面文字并复制

时间:2017-02-03 10:18:41

标签: excel vba excel-vba find

我有一本工作手册来定义两部分之间的清晰度。 我需要将mm的(维度)与数字复制到另一个工作簿。

我尝试了录制宏,但我找不到任何解决方案。

Excel Picture

3 个答案:

答案 0 :(得分:1)

你可以试试这个:

Option Explicit

Sub main2()
    Dim destinationWS As Worksheet
    Dim cell As Range
    Dim clearances As Variant
    Dim iClearance As Long

    Set destinationWS = Workbooks("destinationWorkbookName").Worksheets("destinationWorksheetName") '<--| change "destinationWorkbookName" and "destinationWorksheetName" to your actual names

    With Range("C1", Cells(Rows.Count, "C").End(xlUp))
        .AutoFilter Field:=1, Criteria1:="*mm*"
        If Application.WorksheetFunction.Subtotal(103, .Cells) > 1 Then
            With .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeVisible)
                ReDim clearances(1 To .Count)
                For Each cell In .Cells
                    iClearance = iClearance + 1
                    clearances(iClearance) = GetClearance(cell.Value)
                Next cell
            End With
            destinationWS.Range("A1").Resize(UBound(clearances)).Value = Application.Transpose(clearances)
        End If
        .Parent.AutoFilterMode = False
    End With
End Sub

Function GetClearance(strng As String) As String
    Dim word As Variant

    For Each word In Split(strng, " ")
        If InStr(word, "mm") > 0 Then
            GetClearance = word
            Exit For
        End If
    Next
End Function

答案 1 :(得分:1)

当我运行宏时,我得到了下面的图片:(

我们可以将间隙放在同一部分行的D列上吗?

图片 ----&gt; Macro result

答案 2 :(得分:0)

我自己解决了我的问题。这个标题可以关闭。

由于

user$H_AUDIOID  TRAAAAW128F429D538.h5   TRAAABD128F429CF47.h5   TRAAADZ128F9348C2E.h5   TRAAAEF128F4273421.h5   TRAAAFD128F92F423A.h5   TRAAAMO128F1481E7F.h5   TRAAAMQ128F1460CD3.h5   TRAAAPK128E0786D96.h5   TRAAARJ128F9320760.h5   TRAAAVG12903CFA543.h5   TRAAAVO128F93133D4.h5   TRAABCL128F4286650.h5   TRAABDL12903CAABBA.h5
1   1   0   0   0   0   0   0   0   0   0   0   0   0
2   0   1   1   0   0   0   0   0   0   0   0   0   0
3   0   0   0   1   1   1   1   1   1   0   0   0   0
4   0   0   0   0   0   0   0   0   0   1   1   1   1