gpt4 book ai didi

excel - 仅对某些行使用代码

转载 作者:行者123 更新时间:2023-12-04 21:20:49 26 4
gpt4 key购买 nike

我正在寻找一种从我的函数中排除某些行的方法。到目前为止,这是我的代码:

Dim W As Worksheet
Set W = ActiveSheet

Dim Last As Integer
Last = W.Range("Z2").End(xlToLeft).Column

If Last = 1 Then Exit Sub


Dim i As Integer
Dim j As Integer

For i = Last + 1 To 11

W.Cells(1, i).ClearContents

For j = 3 To 6
W.Cells(j, i).ClearContents
Next j

For j = 8 To 12
W.Cells(j, i).ClearContents
Next j

For j = 14 To 15
W.Cells(j, i).ClearContents
Next j

For j = 18 To 22
W.Cells(j, i).ClearContents
Next j

For j = 24 To 25
W.Cells(j, i).ClearContents
Next j

Next i

我正在尝试缩短代码并尝试使用数组但没有成功。任何帮助,将不胜感激!

最佳答案

尝试,

dim lc as long
with w
lc = .Range("Z2").End(xlToLeft).Column
if lc = 1 then exit sub
application.intersect(.range("1:1, 3:6, 8:12, 14:15, 18:22, 24:25"), _
.range(.columns(lc+1), .columns(11))).clearcontents
end with

关于excel - 仅对某些行使用代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50401978/

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