vba Excel vba代码清除列和行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13046484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel vba code to Clear column and row
提问by user1770752
Need vba code to Clear column from A to J and row from 21 to 200. Below code is clearing the column till end, need to delete till column J
需要vba代码来清除从A到J的列和从21到200的行。下面的代码是清除列直到结束,需要删除直到列J
Function ClearSummary()
Const TestName_Col = "B"
Const FirstRow_Num = "21"
MaxRowNumber = Range(TestName_Col & "200").End(xlUp).Row
If (MaxRowNumber > FirstRow_Num) Then
'select all rows in range & clear
CellReference = FirstRow_Num & ":" & MaxRowNumber
Rows(CellReference).Select
Selection.ClearContents
Selection.Hyperlinks.Delete
Selection.Font.Underline = xlUnderlineStyleNone
Selection.Font.ColorIndex = 0
End If
End Function
回答by CustomX
This should do the trick!
这应该可以解决问题!
Range("A21:J200").Clear
Thumbs up to Chris for teaching me a new method!
感谢 Chris 教我一种新方法!
回答by foochow
A spin off of t.thielemansanswer for those who do not want to lose things such as formatting or data validation
一个分拆的t.thielemans答案为那些谁不想失去的东西,如格式化或数据验证
Range("A21:J200").ClearContents
Range("A21:J200").ClearContents
This will ensure that you keep everything except the current value of the cells selected.
这将确保您保留所选单元格的当前值以外的所有内容。