[英]Delete cells from specific columns using a specific range
I am trying to write a VBScript to delete the contents of cells in columns F, S
and T
from row 1492
to 17910
. 我试图编写一个VBScript来删除行
1492
至17910
F, S
和T
列中单元格的内容。 I only know how to delete an entire row using .Rows(X).EntireRow.Delete
My idea was just loop through the rows and delete the data in the cells which are in that range, but I don't know how to delete contents in one specific cell. 我只知道如何使用
.Rows(X).EntireRow.Delete
删除整行。我的想法是循环浏览各行并删除该范围内的单元格中的数据,但是我不知道如何删除内容在一个特定的单元格中。
You can use the Range()
function to specify your three ranges and call the Clear
method on each range to remove all values/formatting/etc. 您可以使用
Range()
函数指定三个范围,并在每个范围上调用Clear
方法以删除所有值/格式/等。
Assuming your Excel application variable is named objExcel
and your range is located on your active sheet, you could use the following: 假设您的Excel应用程序变量名为
objExcel
并且您的范围位于活动工作表上,则可以使用以下命令:
With objExcel.ActiveSheet
.Range("F1492:F17910").Clear
.Range("S1492:S17910").Clear
.Range("T1492:T17910").Clear
End With
Since Range()
can accept multiple ranges, you could even do this in a single call: 由于
Range()
可以接受多个范围,因此您甚至可以在一个调用中执行此操作:
objExcel.ActiveSheet.Range("F1492:F17910,S1492:S17910,T1492:T17910").Clear
If you just want to clear the contents but keep the formatting, use ClearContents
instead. 如果您只想清除内容但保留格式,请改用
ClearContents
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.