excel - 如何将一个单元格的值限制为另一个单元格的值?
问题描述
我有一张满是数字的桌子。我需要一个宏脚本,它将目标值与得分值进行比较。如果分值高于目标值,则将目标值更改为分值。
有人可以帮助我吗?
我试图在一个单元格上应用以下代码,但它不起作用。
Sub check_value()
If Cells(8, 23).Value < Cells(8, 24).Value Then
Cells(8, 23).Value = Cells(8, 24).Value
End If
End Sub
解决方案
我认为这可能会对您有所帮助:
Option Explicit
Sub test()
Dim LastRow As Long, Row As Long, Target As Long, Score As Long, LastColumn As Long, Column As Long
With ThisWorkbook.Worksheets("Sheet1")
LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For Column = 2 To LastColumn
For Row = 2 To LastRow Step 2
Target = .Cells(Row, Column).Value
Score = .Cells(Row + 1, Column).Value
If Score > Target Then
.Cells(Row, Column).Value = Score
End If
Next Row
Next Column
End With
End Sub
推荐阅读
- swagger - 如何使用 go-swagger 服务器公开 swagger.json?
- openlayers - 没有的 KML/OpenLayers GroundOverlay 元素
标签没有加载到地图上? - variables - 如何为销售的总 WooCommerce 变体设置最大库存水平,而不考虑单个变体库存水平
- python-3.x - 计数矢量化器和拟合函数的 Python 列表错误
- tensorflow - Tnesorflow:STFT 的梯度误差
- javascript - 如何在新的 window.open 上启动 jquery 并避免“Uncaught ReferenceError: $ is not defined”错误?
- reactjs - “警告:无法在未安装的组件上调用 setState(或 forceUpdate)”,但组件没有 setState?
- ios - 资产交换流程改变了吗?
- javascript - 使用 mocha webdriver 在浏览器中测试时出现“ReferenceError:文档未定义”
- python - python请求对url进行编码