gpt4 book ai didi

vba - 清除未 protected 单元格的按钮

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

我是 VBA 的新手。我正在尝试制作一个按钮来清除我未 protected 单元格中的值。我有一张 protected 工作表,但我想确保只清除未 protected 单元格。我需要一个单元格范围吗?提前致谢

最佳答案

工作表是 protected , 单元格是 锁定 .

试试这个:

Sub ClearStuff()
Dim r As Range, rClear As Range
Set rClear = Nothing
For Each r In ActiveSheet.UsedRange
If r.Locked = False Then
If rClear Is Nothing Then
Set rClear = r
Else
Set rClear = Union(rClear, r)
End If
End If
Next r
rClear.Clear
End Sub

编辑#1:这将清除 内容 只要:
Sub ClearStuff()
Dim r As Range, rClear As Range
Set rClear = Nothing
For Each r In ActiveSheet.UsedRange
If r.Locked = False Then
If rClear Is Nothing Then
Set rClear = r
Else
Set rClear = Union(rClear, r)
End If
End If
Next r
rClear.ClearContents
End Sub

关于vba - 清除未 protected 单元格的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45286070/

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