VBA使用通配符进行搜索

时间:2014-08-11 22:08:12

标签: excel vba

如果可能的话,我想创建一个VBA宏来搜索整个列A中包含字母RU的任何单词(区分大小写,如果可能的话)。然后我希望它能够复制这些单词并将它们粘贴在从A1开始的新表格上,然后是A2,等等。我知道如何设置范围,但我甚至不知道如何开始编写休息。任何帮助将不胜感激。

最诚挚的问候。

1 个答案:

答案 0 :(得分:0)

考虑:

Sub RUthere()
    Dim RU As String, N As Long, K As Long, _
        s1 As Worksheet, s2 As Worksheet, r As Range, _
        v As Variant
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    RU = "RU"
    K = 1
    N = s1.Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To N
        Set r = s1.Cells(i, "A")
        v = r.Value
        If InStr(1, v, RU) > 0 Then
            r.Copy s2.Cells(K, "A")
            K = K + 1
        End If
    Next i
End Sub