如果大于以前的单元格在不同的位置

我必须检查,如果单元格“C”中的值大于0,但小于前一个单元格“E”中的值,例如检查单元格“3C”处的值是否大于0,但小于比单元格“2E”中的值小。 我已经把它放在RGB的颜色错误包括单元格红色。 我也使用UserFormsinput。

这是我在Excel VBA中的代码:

X = Cells(j, "C").Value d = Cells(j, "E").Value c = Cells(j, "E-1").Value If X >= c And X < 0 Or X < 0 Or X >= c Then Cells(j, "C").Interior.Color = 255 UserForm1.inpBox.Value = j UserForm1.Label1.Caption = (j & ". Row has an error!") UserForm1.Show Cells(j, "C") = UserForm1.inpBox.Value Cells(j, "C").Interior.Color = RGB(255, 255, 255) End If 

我知道这里有一个错误,但是我不知道该怎么处理它的工作:

  X = Cells(j, "C").Value d = Cells(j, "E").Value c = Cells(j, "E-1").Value If X >= c And X < 0 Or X < 0 Or X >= c Then 

使用Range.Offset(rowOffset, colOffset)方法:

 c = Cells(j, "E").Offset(0, -1).Value ' addresses "previous" column c = Cells(j, "E").Offset(-1, 0).Value ' addresses "previous" row