Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 基于比较两行中的每个单元格更改一行单元格的格式_Excel_Vba - Fatal编程技术网

Excel 基于比较两行中的每个单元格更改一行单元格的格式

Excel 基于比较两行中的每个单元格更改一行单元格的格式,excel,vba,Excel,Vba,在excel 2016中,我使用查询来收集数据。在该数据中,包括当前库存和未来2天生产所需的数量。我想强调的是,当库存低于所需数量时。当我使用条件格式时,它最初看起来很好,但是当我使用更多数据更新时,条件格式的范围就被破坏了。使用VBA做这件事的好方法是什么 没有更多的细节,很难知道什么是妥协。我猜条件格式的范围要么不包括新记录,要么被其他记录更改。修改条件格式的范围以包含整行可以解决问题吗?e、 g.将$A$1:$B$5更改为$A:$B 编辑: 好啊请尝试每次清除和重置条件格式的VBA Sub

在excel 2016中,我使用查询来收集数据。在该数据中,包括当前库存和未来2天生产所需的数量。我想强调的是,当库存低于所需数量时。当我使用条件格式时,它最初看起来很好,但是当我使用更多数据更新时,条件格式的范围就被破坏了。使用VBA做这件事的好方法是什么


没有更多的细节,很难知道什么是妥协。我猜条件格式的范围要么不包括新记录,要么被其他记录更改。修改条件格式的范围以包含整行可以解决问题吗?e、 g.将$A$1:$B$5更改为$A:$B

编辑: 好啊请尝试每次清除和重置条件格式的VBA

Sub Format()
  With ActiveSheet.Rows("$2:$2") ''Select rows your working with
    .FormatConditions.Delete  '' Clear out exising Conditional Formatting in selection
    .FormatConditions.Add Type:=xlExpression, Formula1:="=(A$1>A$2)"  ''Formula where condition is true
    .FormatConditions(.FormatConditions.Count).Interior.Color = 65535 ''Set formatting you color yellow
  End With
End Sub

Greg_D我刚找到一个解决方案,看到你刚刚发布了一个解决方案。我试过你的,效果不错。我走了另一条路

Sub Inventory_format()Dim cell As Range
对于RangeSeqInv中的每个单元格

'需要将公司库存添加到QTYneed “库存*90%低于所需数量,但以红色突出显示警告” '使用命名的范围下限,因此可以在发电机设定点工作表中更改

如果cell.Value*1-RangeLow_limit cell.Interior.Color=VBA.ColorConstants.vbRed

“库存*70%低于黄色警告要求

ElseIf cell.Value*1-范围上限
End Sub

为什么条件格式会受损?如果设置为这两行,并且您没有使用锁定的单元格引用,则格式应根据需要展开,而不受影响。我认为你不需要VBA来实现这一点-你能分享你当前的条件格式规则吗?适用于这一点的规则正在受到损害。当我输入动态范围时,它会转换为实际地址。然后,当我添加更多记录并更新“Applied to not update properlyGreg”查询时,我添加了另一张显示条件格式规则管理器屏幕截图的图片。开始时,我将格式应用于整行。然后,当数据集从较小的无设置行和列更改为较大的数据集时,将应用于更改我的答案。希望这是一个适合你的解决方案。