如何在 Excel 中的通配符文字中按 SearchFormat 進行搜尋?

如何在 Excel 中的通配符文字中按 SearchFormat 進行搜尋?

例如,工作表中有 100(行)x 20(列)儲存格,每個儲存格有 5 行。有些行是紅色的,有些行是帶有刪除線的,等等。如何找到所有有刪除線的行?我怎樣才能只透過 進行搜尋SearchFormat

我已經嘗試過 Excel find with format,但它不適用於部分單元格。如果5條線全部為紅色,則可以找到它們;但如果只有2條紅色線,其他3條線正常,即使match entire cell contents是也找不到這2條線不是檢查過。

答案1

您將需要一個VBA解決方案:

下面是一個幫助您入門的範例宏,它在活動工作表(從活動儲存格右側的一個儲存格開始)中搜尋包含文字常數的儲存格,然後在儲存格中一次搜尋一個字元的文字以查找紅色。它停止並選擇它找到的第一個包含紅色文字的儲存格

Sub FindColorInCells()
    Dim n As Long
    Dim i As Long, j As Long
    Dim cl As Range
    Dim r As Range

    Set r = ActiveSheet.UsedRange
    i = ActiveCell.Row - r.Row + 1
    If i > r.Rows.Count Or i < 0 Then i = 1
    j = ActiveCell.Column - r.Column + 1
    If j > r.Columns.Count Or j < 0 Then j = 1
    i = (r.Columns.Count * (i - 1) + j) Mod r.Cells.Count + 1
    j = r.Cells.Count
    Do While i <> j
        With r(i)
            If Not .HasFormula Then
                If Len(.Value) > 0 Then
                    If TypeName(.Value) = "String" Then
                        For n = 1 To .Characters.Count
                            If .Characters(n, 1).Font.ColorIndex = 3 Then
                                ' found red
                                .Select
                                Exit Sub
                            End If
                        Next
                    End If
                End If
            End If
        End With
        i = i Mod j + 1
    Loop
End Sub

相關內容