作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我看过this非常相似的问题,我认为用户@SQL Police 的回答很棒!但我不知道如何修改或调整它以产生我正在寻找的结果。这是我的(类似但不同的)问题:
我想删除不在第 24 - 26 列中的所有内容,但也不在第 1 - 6 行中。
我有代码可以单独执行,但不能一起执行。
删除指定列:
Sub ColClear()
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Range(ws.Columns(1), ws.Columns(23)).ClearContents
ws.Range(ws.Columns(27), ws.Columns(ws.UsedRange.End(xlToRight).Column)).Clear
End Sub
删除指定行:
Sub RowClear()
With Sheets("SheetName")
.Rows(7 & ":" & .Rows.Count).ClearContents
End With
End Sub
But how can I do both at once? (The intersection of the two ranges, not the union)
最佳答案
适应你的要求,基本思路是得到双方的范围然后ClearContents
分别地:
Option Explicit
Private Sub Test()
Dim ws As Worksheet
Set ws = ActiveSheet
With ws
Dim bottomLeftRng As Range
Set bottomLeftRng = .Range(.Cells(7, 1), .Cells(.Rows.Count, 23))
Dim bottomRightRng As Range
Set bottomRightRng = .Range(.Cells(7, 27), .Cells(.Rows.Count, .Columns.Count))
End With
bottomLeftRng.ClearContents
bottomRightRng.ClearContents
End Sub
关于excel - 如何清除除 X、Y 和 Z 列和 A、B、C 行之外的所有数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72639603/
我是一名优秀的程序员,十分优秀!