如何使用For循环替换偏移单元格

ksm*_*144 3 excel vba excel-vba

所以我写了一个For循环代码,试图搜索包含以"GE90"开头的描述的单元格的特定列(列M),并用"GE90 Hold"替换adjecent偏移单元格(C列).

我以为我正确使用了代码但由于某种原因它似乎不起作用.

Dim Cell
For Each Cell In Range("M2:M" & LastRow)
    If Cell.Value = "GE90*" Then
        Cell.Offset(, -10).Value = "GE90 Hold"
    End If

Next Cell
Run Code Online (Sandbox Code Playgroud)

nee*_*lsg 5

您的问题实际上是您假设星号"GE90*"是通配符,但实际上,您的代码正在寻找文字值"GE90*".更改您的代码如下:

Dim Cell
For Each Cell In Range("M2:M" & lastrow)
    If Left(Cell.Value, 4) = "GE90" Then
        Cell.Offset(, -10).Value = "GE90 Hold"
    End If

Next Cell
Run Code Online (Sandbox Code Playgroud)