返回列表 上一主題 發帖

"find "的問題

Sub Ex1_20171031()
   
    Application.ScreenUpdating = False
   
    Worksheets(2).Select
   
    ROW1 = Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row
   
    Cells.ClearFormats

    Sheets(1).Select

    For I = 1 To ROW1
        f1 = Worksheets(2).Cells(I, "A").Value
        Range("B1").Select
        On Error Resume Next                    '忽略錯誤繼續執行 VBA 代碼,避免出現錯誤信息
        '搜尋字串========================================================================
        Cells.Find(What:=f1, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , MatchByte:=False, SearchFormat:=False).Activate
        
        Worksheets(2).Cells(I, "B").Value = ActiveCell.Value
        If Worksheets(2).Cells(I, "B").Value = "" Then
            Worksheets(2).Range("A" & I).Interior.Color = RGB(128, 0, 128)
        End If
    Next
    Sheets(2).Select
    Range("B1:B" & ROW1).ClearContents
   
    Application.ScreenUpdating = True
End Sub

test.zip (19.76 KB)

TOP

        靜思自在 : 多做多得。少做多失。
返回列表 上一主題