我有下面的代码,实际上我想根据I16的值重命名工作表。然而,如果目标地址为空/空,我希望退出子。(代码的这一部分不起作用)。
如果有人能建议我如何解决这个问题,我们将不胜感激。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("I16")
Dim WSname As String
WSname = Range("I16").Value
If KeyCells Is Nothing Then Exit Sub
Sheet23.Name = "BISSB"
Sheet25.Name = "RMIB"
Sheet26.Name = "MORIB"
Worksheets(WSname).Name = "Stage 3 V1"
End Sub
发布于 2017-09-27 02:58:54
而不是
If KeyCells Is Nothing Then Exit Sub
使用
If IsEmpty(KeyCells) Then Exit Sub
ISEMPTY函数可用于检查空白单元格。如果单元格为空,它将返回TRUE
else FALSE
。
发布于 2017-09-27 02:57:27
取代:
If KeyCells Is Nothing Then Exit Sub
通过以下方式:
If Trim(WSname) = "" Then Exit Sub
:您已经在代码中使用了Set KeyCells = Range("I16")
,因此您设置了KeyCells
范围,因此永远不会是Nothing
。您希望检查KeyCells
范围的值,并且有您的WSname
字符串变量。
发布于 2017-09-27 02:58:55
您已经声明并将KeyCells设置为"I16“。这就是为什么如果条件不能工作-因为KeyCells已经包含单元格。询问WSname = "“,或者以其他方式检查它是否包含值。
https://stackoverflow.com/questions/46446091
复制相似问题