Excel VBA : How to clear contents for specified cells when another cell contains specific text or string

标签 excel vba

如果某个单元格包含特定文本,我在尝试查找 VBA 代码以删除多个特定单元格时遇到了一些麻烦。此电子表格也可以运行接近 100k 行,但会因数据拉取而异。

特定的 VBA 将能够执行以下操作:

如果单元格 J3 等于 #N/A、空白或 0,则清除单元格 J3:K3 和 P3:X3 的内容,然后重复直到到达 J 列的底部。

提前致谢

最佳答案

How to clear contents for specified cells when another cell contains specific text or string


Dim cellToClear As Range
Dim cellToCheck As Range
Dim specificText As String
If cellToCheck.Value = specificText Then cellToClear.ClearContents

"I'm having some trouble trying to find VBA code "



这些链接包含 VBA 代码,您可以在尝试不再遇到问题时使用这些代码。它们包含您可以粘贴到项目中并根据需要进行修改的示例。

This link has examples of how to read the contents of a cell .

范围是工作表中的一组一个或多个单元格。您可以对范围执行操作,它将影响范围内的所有单元格。 This link has examples of how to work with a range .

循环是程序重复相同的步骤序列时,通常直到满足特定条件。 You can find examples of different loops here .

关于Excel VBA : How to clear contents for specified cells when another cell contains specific text or string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58210572/

相关文章:

excel - 在 WCF 数据服务中指定空 IQueryable 中的列?

excel - 使用范围,如何将 .COPY DESTINATION 粘贴为值

python - 通过 Excel VBA 运行 Python 脚本

excel - 对多个文件运行 Excel 宏

python - win32com 相当于 xlrd 的 sheet.ncols

excel - 在 BIRT 上的表格详细信息中垂直合并单元格

vba - winsock 连接功能仅适用于高速连接

string - VBA 字符串清理

excel - 重新打开时用户窗体会保持清除值

excel - 我需要将多个用户选择的行复制到不同的工作表。问题是,每次宏运行时选择的行都不同