返回列表 上一主題 發帖

"find "的問題

"find "的問題

各位大大:

本人是學者,有一個問想問問, 附件中,如果我想在sheet2的資料相比sheet1 的資料,如果sheet2有而sheet1沒有,那就sheet2會顯示紫色標記

但我發覺只能做到有資料就會有標記,不論是否相同的資料也會標記,

請各位大大幫忙指教,謝謝

test.rar (15.16 KB)

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

格式化無法跨頁 工作表2!C1:C7設輔助=COUNTIF(工作表1!A:A,A1)

A1:A7格式化=A1=C1
google"EXCEL迷"  blog  或google網址:https://hcm19522.blogspot.com/

TOP

回復 1# mdr0465
  1. Sub Ex()
  2.     Dim rng, rng2 As Range
  3.    
  4.     Application.ScreenUpdating = False
  5.    
  6.     With Sheets(2)
  7.      .Range("a1:a18").Interior.ColorIndex = xlNone
  8.        For Each rng2 In .Range("a1:a18").SpecialCells(xlCellTypeConstants)
  9.          If Sheets(1).Range("A1:A18").Find(rng2, lookat:=xlWhole) Is Nothing Then rng2.Interior.ColorIndex = 47
  10.        Next
  11.     End With
  12.    
  13.     Application.ScreenUpdating = True

  14. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 脾氣嘴巴不好,心地再好也不能算是好人。
返回列表 上一主題