excel - 如何比较行之间的值
问题描述
我在这里需要帮助。我有一个包含超过 6K 数据的电子表格。我需要使用 VBA比较“ MOVE_IN_QTY ”和“ MOVE_OUT_QTY ”之间的值。这里的问题是我需要在代码列中的代码从“ CV64 ”和“ TW78 ”更改后立即比较值。我用红色突出显示的值和我用蓝色和黄色突出显示的代码。我将不胜感激任何帮助。谢谢。
解决方案
在这里做一些假设:
- 搬入和搬出始终是数字。
- 使用 =,<,> 过程计算移动编号。
- 需要根据结果采取未知的进一步行动。
它还有助于包括您尝试过的内容和无效的内容。
Sub ReviewData() Dim wkbk As Workbook Dim xsheet As Worksheet Dim codeColumn As String, moveIN As String, moveOUT As String Dim rowCount As Double Set wkbk = ThisWorkbook Set xsheet = wkbk.Worksheets("Sheet1") 'change sheet name here codeColumn = "B" ' change column letter here moveIN = "C" 'set move in column moveOUT = "D" 'set move out column 'this will loop through the Code column until the last set of data. rowCount = xsheet.Range(codeColumn & xsheet.Rows.Count).End(xlUp).Row 'find last row For x = 2 To rowCount 'checks if code transitions from one code to another If not xsheet.Range(codeColumn & x).Value = xsheet.Range(codeColumn & x + 1).Value Then If xsheet.Range(moveIN & x).Value = xsheet.Range(moveOUT & x + 1).Value Then 'do something if the code is the same Else xsheet.Range(codeColumn & x).Interior.ColorIndex = 3 MsgBox ("Row: " & x & " is different") 'comment this out not to get the message End If Else End If Next x End Sub
推荐阅读
- java - 通过 Jackson/Spring REST 资源反序列化枚举字段
- entity-framework-core - 通过 EF Core 从数据库生成 C# 类
- flask - Flask 不适用于 Chrome,但适用于 Safari
- macos - Makefile 找不到可执行文件 - 没有这样的文件或目录
- shacl - Shacl sh:qualifiedValueShape 表达式缩写
- sql - 为什么在 case 命令中“不工作”?
- javascript - 如何在垂直列表中显示数组输出?
- vue.js - 如何禁用 vue-simple-calendar 中的特定日期?
- r - 如何将函数应用于向量的所有对
- rust - 如何在向量中打印json对象