gpt4 book ai didi

vba - 工作表更改事件

转载 作者:行者123 更新时间:2023-12-04 21:55:10 36 4
gpt4 key购买 nike

我有下面的代码,我实际上想根据 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

最佳答案

代替:

If KeyCells Is Nothing Then Exit Sub

和:
If Trim(WSname) = "" Then Exit Sub

解释 : 你已经使用了 Set KeyCells = Range("I16")在你的代码中,所以你设置你的 KeyCells范围,因此它永远不会是 Nothing .
您想检查 KeyCells 的值范围,你有你的 WSname字符串变量。

关于vba - 工作表更改事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46446091/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com