vba 清除使用范围外的单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17549250/
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
Clear cells out of the used range
提问by lcrmorin
In one of my macros I loop trough used range, but the used range is way bigger than the actual used range, therefore the macro is impossible to run. I think that cells outside the actual used range may have other impacts on my code such as error "too many cell format" with only one cell.
在我的一个宏中,我循环使用范围,但使用范围比实际使用范围大得多,因此宏无法运行。我认为实际使用范围之外的单元格可能会对我的代码产生其他影响,例如错误“单元格格式太多”,只有一个单元格。
How can I clean cells outside my used range so that they are not taken into account in my Used range ?
我如何清理我使用范围之外的单元格,以便在我的使用范围内不考虑它们?
回答by markblandford
The Used Range not truly reflecting what is the actual used range is a common issue and just requires some basic cleaning up of the sheet.
使用范围不能真正反映实际使用范围是一个常见问题,只需要对工作表进行一些基本清理。
Check out this on the Microsoft Support site: http://support.microsoft.com/kb/244435
在 Microsoft 支持站点上查看此内容:http: //support.microsoft.com/kb/244435
回答by Steph Locke
You can delete everything outside of your actual used range.
您可以删除实际使用范围之外的所有内容。
You can either do this manually with selecting a row and ctrl+shift+down (and ctrl+shift+right with a column selected) or you can do it programatically by identifying where your data actually ends (either via a COUNTA or xlRight style of command) and then delete everything after those points.
您可以通过选择一行并 ctrl+shift+down(以及 ctrl+shift+right 并选择一列)来手动执行此操作,也可以通过识别数据实际结束的位置(通过 COUNTA 或 xlRight 样式的命令),然后删除这些点之后的所有内容。
The manual way is good for if it's just a one one off cleanup operation, and if you're doing it in the macro then you may as well just use the method for determining the range to keep to go straight to selecting it, and not bothering to delete outside of the range.
手动方式很适合,如果它只是一个一次性的清理操作,如果你在宏中进行,那么你也可以使用确定范围的方法直接选择它,而不是麻烦删除范围之外。