如果单元格包含的话

时间:2018-05-06 16:33:21

标签: excel vba excel-vba

我正在编写一个基本的宏,如果另一个单元格中有某个单词,它将帮助用一个值填充单元格。这是我的代码:

Sub SSS()
    For i = 2 To lastrow
        If Cells(i, 4).Text = ("x") Then Cells(i, 2) = "a"
    Next i
End Sub

但是单元格d2也包含其他单词,所以如果我在单元格d2中有“x a”,则单元格b2中不返回任何值。我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

You could use regex with word boundary included in the pattern. Assuming it is truly a word that you are looking for.

Code:

  <input #search (keyup)="searchTerm.next(search.value)">
  <div *ngIf="results"> 
    <!--slice is optional-->
    <div *ngFor="let item of results |slice:0:10">
         {{item.descripcion}}
    </div>
   </div>

Example data with output:

Data and output

Regex info:

Regex