首页 > 解决方案 > 我是初学者,如何在 VBA excel 中获取变量中的单元格值?

问题描述

我正在尝试比较 excel 列中的单元格值。如果数字从 8 变为 7,我必须插入一个空白行。所以我试图取变量中的值,然后比较它们。但我无法在变量中设置值:(

标签: excelvba

解决方案


简要说明如何比较:

Sub Compare()

Dim CellValue As Integer, CompareWithValue As Integer

CellValue = Sheet1.Range("A1").Value '<= The value in the A1 of Sheet1
CompareWithValue = Sheet1.Range("A2").Value '<= The value in the A2 of 
                    Sheet1

If CellValue > CompareWithValue Then '<= Compare if CellValue is greater than 
CompareWithValue (here you can also use < or =)
'what do you want to happen if the above condition is true
End If

End Sub

推荐阅读