VBAselect案例插入
我正在尝试编写一个select case函数来确定D列中的文本和单元格A2中的值,并分别取决于文本和值,并在与活动单元格相邻的列中插入适当的值。
这是我到目前为止(显然这将增长考虑到列D和A2中的所有variables)
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "D:D" Then Select Case ActiveCell.TextPart = "" Case ActiveCell.TextPart = "Cat I(a)" And Range("A2").Value = 1: ActiveCell.Offset (0,1).Insert.Value "1"
谁能告诉我我做错了什么? 我是我的Uni论文的VBA新手写作代码。
Select Case ActiveCell.TextPart = ""
这select了比较的布尔结果。 因为如果TextPart
为空,后续的Case ActiveCell.TextPart = "Cat I(a)"
实际上永远不可能是“case”。
如果你想selectTextPart
:
Select Case ActiveCell.TextPart Case "Cat I(a)" If Range("A2").Value = 1 then ActiveCell.Offset (0,1).Insert.Value "1"