【发布时间】:2020-02-13 16:18:25
【问题描述】:
正如标题所说,我想验证一个条目并将其与特定单元格(iLastRow,8)进行比较。 为此,我把这个 lign 放在我的其他条件之前。
Test = (TextBox2.Text) > ws.Cells(iLastRow, 8)
If Test = True Then
MsgBox "Not enough quantity in stock!"
Else
但消息每次都会显示,即使数字较低。 奇怪的是,如果第 4 到第 7 列之间的所有单元格都被填满,代码运行良好,如果我删除超过 2 个侧行的内容,则代码不再工作。 这是我的全部代码:
Private Sub CommandButton1_Enter()
Dim emptyRow As Long
Dim ws As Worksheet
Set ws = ActiveSheet
ActiveSheet.Name = "Micrux"
Dim iLastRow As Long, iFound As Long
Dim rng, bEmpty As Boolean, c As Integer
Dim Test As Boolean
bEmpty = True
With ws
iLastRow = .Range("A" & .Rows.Count).End(xlUp).Row
Set rng = .Range("A1:A" & iLastRow + 1).Find(ComboBox1.Value, _
After:=.Range("A" & iLastRow + 1), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
SearchDirection:=xlPrevious)
Test = (TextBox2.Text) > ws.Cells(iLastRow, 8)
If Test = True Then
MsgBox "Not enough quantity in stock!"
Else
If rng Is Nothing Then
iFound = iLastRow + 1
Else
iFound = rng.Row
For c = 4 To 7
If Len(.Cells(iFound, c)) > 0 Then bEmpty = False
Next
If bEmpty = False Then
iFound = iFound + 1
.Cells(iFound, 1).EntireRow.Insert xlShiftDown
.Cells(iFound, 7).Value = TextBox2.Text
.Cells(iFound, 6).Value = TextBox3.Text
.Cells(iFound, 5).Value = ComboBox2.Value
.Cells(iFound, 4).Value = TextBox1.Text
Else
.Cells(iFound, 7).Value = TextBox2.Text
.Cells(iFound, 6).Value = TextBox3.Text
.Cells(iFound, 5).Value = ComboBox2.Value
.Cells(iFound, 4).Value = TextBox1.Text
End If
End If
End If
End With
Unload Me
End Sub
提前致谢
【问题讨论】:
-
试试
Test =VAL(TextBox2.Text) > VAL(ws.Cells(iLastRow, 8).Value) -
感谢 Siddhart Rout,它适用于 iFound 但与 iLastRow 不在同一行,它只是不显示消息..
-
单步执行代码并检查
iLastRow和ws.Cells(iLastRow, 8).Value和TextBox2.Text的值是什么 -
最后它是行不通的,除非我投入了非常高的价值..
-
你看到我的最后一条消息了吗?
标签: excel vba textbox compare cell