因此,我编写了一个 For 循环代码,尝试在数据的特定列(M 列)中搜索包含以“GE90”开头的描述的单元格,并用“GE90 Hold”替换相邻的偏移单元格(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
最佳答案
您的问题实际上是您假设 "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
关于vba - 如何使用For循环替换偏移单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26675284/