Выделите ячейку, если в тексте ячейки есть определенное слово - PullRequest
0 голосов
/ 13 марта 2019

Я хочу красным цветом выделить все ячейки, которые содержат слова «Цвет» и «Ширина».

С помощью кода, который я имею, я ввожу значение ячейки.Я хочу ввести слова "Цвет" и "Ширина".

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

enter image description here

1 Ответ

0 голосов
/ 13 марта 2019

Вы можете использовать Like.

edit - обновлено, чтобы можно было вводить несколько терминов (не проверено)

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...