如果左侧的值"Home"则写入 True。

  • 本文关键字:True Home 如果 vba excel
  • 更新时间 :
  • 英文 :


>如果左侧的值是"home",我需要在 B 列中粘贴 true 的宏,如果不是,则粘贴 false。我试图使用 If 和 Else staments 但当我的值是字母时,我无法弄清楚如何创建代码。

这应该有效,但未经测试:

Sub CheckColumn()
Dim maxrow As Integer, i As Integer
With ActiveSheet
    maxrow = .UsedRange.Rows.Count
    For i = 1 To maxrow
        If .Cells(i, 1) = "home" Then
            .Cells(i, 2) = "true"
        Else
            .Cells(i, 2) = "false"
        End If
    Next i
End With
End Sub

再。。。公式方法会容易得多。

最新更新