gpt4 book ai didi

vba - 偏移/调整先前定义的范围

转载 作者:行者123 更新时间:2023-12-04 21:34:43 29 4
gpt4 key购买 nike

我正在尝试从第 4 到 9 页以及第 12 和 13 页上的单元格中清除所有内容(包括图像)。我有以下代码,但它正在清除第 3-9 和 12-15 页中的内容,我不知道为什么。

有什么想法吗?

Sub ClearContents()
Dim i As Integer
For i = 4 To 9 And 12 And 13
Sheets(i).Cells.Clear
Sheets(i).Pictures.Delete

Next i

最佳答案

试试下面的代码:

Option Explicit

Sub ClearContents()

Dim i As Long
Dim Sht As Worksheet
Dim PicObj As Object

' loop through all worksheets in your workbook
For Each Sht In ThisWorkbook.Sheets
Select Case Sht.Index
Case 4 To 9, 12, 13
Sht.Cells.Clear

' loop through all shapes in your worksheet and delete them all
For Each PicObj In Sht.Shapes
PicObj.Delete
Next PicObj

Case Else '<-- for future cases, if you'll need
'do nothing
End Select
Next Sht

End Sub

关于vba - 偏移/调整先前定义的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42009651/

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