VBA手工输入关键字在当前工作表中模糊查找,并将目标整行复制到另一工作表

Sub cha()
Dim result As String, str1 As String
Dim hang As String
Dim hha As Integer
hha = 0
    Dim c As Range, rng As Range
    result = "航空"
    result = Application.InputBox(prompt:="请输入要查找的值:", Title:="模糊查找", Type:=2)
    If result = "False" Or result = "" Then Exit Sub
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    'Set rng = ActiveSheet.Range("c1").CurrentRegion
    str1 = "*" & result & "*"
   ' Set av = Worksheets("航班")
    Set rng = ActiveSheet.Range("a1:z65535").CurrentRegion
    For Each c In rng.Cells
    'For Each c In av
        If c.Value Like str1 Then
            hha = hha + 1
            c.Interior.ColorIndex = 0 '0恢复默认色 4绿色
            c.EntireRow.Copy Sheets("汇总1").Cells(str(hha), 1)

            hang = c.Row
        End If
    Next
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub

 

posted @ 2022-11-17 15:22  myrj  阅读(550)  评论(0编辑  收藏  举报