Excel IF - 那么有2个动作

时间:2016-09-02 00:14:42

标签: excel vba excel-vba

我有一个宏来检查第J列中单元格的值。根据我需要设置K和L列中的单元格的值,我想使用以下代码:

For Each Cell In TelRange
  With Cell
    If Left(.Value, 3) = 201 Then
      Cell.Offset(0, 1).Value = "Mobile" And Cell.Offset(0, 2).Value = Left(Value, 5)
    End If
  End With
Next Cell

然而,这不起作用。

有人知道如何做到这一点吗?

1 个答案:

答案 0 :(得分:6)

从这个问题来看,它听起来像是1个动作而不是2个,对吗? 尝试将其拆分为两行(AND用于逻辑操作,如A和B)

For Each Cell In TelRange
  With Cell
    If Left(Value, 3) = 201 Then
      Cell.Offset(0, 1).Value = "Mobile"
      Cell.Offset(0, 2).Value = Left(Value, 5)
    End If
  End With
Next Cell

如果它不起作用,请说明发生了什么。错误信息?不更新?

相关问题