簡體   English   中英

如果該單元格文本中有特定單詞,則突出顯示該單元格

[英]Highlight a cell if there is a specific word in the cell's text

我要用紅色突出顯示所有包含單詞“顏色”和“寬度”的單元格。

使用已有的代碼,輸入單元格的值。 我想輸入單詞“顏色”和“寬度”。

Sub test()    

aaa = InputBox("Enter value 1:")
bbb = InputBox("Enter value 2:")

Dim myrange As Range
Set myrange = ThisWorkbook.Worksheets("Tabell").UsedRange

For Each cell In myrange.Cells

    If cell.Value = aaa Or cell.Value = bbb Then
        cell.Interior.Color = 255
    End If

Next

End Sub

在此輸入圖像描述

您可以使用Like

編輯 -更新以允許輸入多個術語(未經測試)

dim terms as new collection, term, deleteMe as boolean

do
    term = Trim(InputBox("Enter value (leave blank to end entry)"))
    if len(term)>0 then
        terms.add term
    else
        exit do
    end if
loop

if terms.count=0 then exit sub '<< no terms to check for

For Each cell In myrange.Cells

    deleteMe = true

    for each term in terms
        if not cell.value like term & "*" then
            deleteMe = false 
            exit for
        end if
    next term

    if deleteMe then cell.value = ""
next cell

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM