vba - 如果值小于另一个单元格值,则清除 Excel 单元格
问题描述
我希望有人可以提供帮助,当值小于另一个单元格中的值时,我需要清除单元格。我确实使用了条件格式,但这会使工作表中的计算更加混乱。
当我将固定整数输入模块时,我使用了指南并且能够删除单元格,但不确定我如何调整它以引用单元格而不是固定数字。
谢谢你。
埃德
解决方案
我相信这就是您在下面寻找的内容,这将从单元格 B1 中获取一个值并与 A 列中的值进行比较,如果这些值小于 B1 中的值,它将清除该单元格的内容:
Sub ClearLowerThan()
Dim c As Range, Rng As Range
Dim LastRow As Long
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
'declare you worksheet, amend as required
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'get the last row with data on Column A
CompareVal = ws.Range("B1").Value
'get the value to compare against, in this case from cell B1
Set Rng = ws.Range("A1:A" & LastRow)
'set the range to compare against the value from B1
For Each c In Rng 'for each cell in the given range
If c.Value < CompareVal Then c.ClearContents
'if value of cell is less than the value to compare against, clear the cell contents.
Next
End Sub
推荐阅读
- wpf - WPF - 菜单中的小白点
- julia - 在 Julia 中使用 JLD2 加载无法找到文件
- c# - AuthorizeFilter 失败时如何返回 403 而不是重定向访问被拒绝
- python - Python PyAutoGUI 返回“ImageNotFoundException”,但“except”不识别为异常
- javascript - 音频完成然后播放按钮图标再次显示
- java - Java AppletViewer 未初始化
- java - 如何将片段的上下文转换为 LifecycleOwner?
- autoit - 如何做到这一点发送(“发送(”$readme 1“)”)?
- kendo-ui - 具有自动完成功能的剑道时间选择器
- sql-server - 是否可以在sql-server中声明没有@符号的变量?