您好,我正在尝试创建Vba代码检查,所生成的Po编号超过104%,因此程序将使用Po。并将生产的零件作为输入,并检查生产的零件是否超过104%并返回错误。
这将允许用户输入电话号码
Public Sub Pobox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim x As Integer
x = 1
Dim trovato As Boolean 'found=trovato
trovato = False
'Dim Labelstyle, Labelcolor As String
'Sheets("PO summary").Activate
Do Until Sheet2.Cells(1 + x, 1) = ""
If Sheet2.Cells(1 + x, 1) = Pobox.Value Or Sheet2.Cells(1 + x, 10) = Pobox.Value Then
Labelstyle = Sheet2.Cells(1 + x, 13)
Labelcolor = Sheet2.Cells(1 + x, 14)
trovato = True
End If
x = x + 1
Loop
'Sheets("INSERT").Activate
If trovato = False And Pobox.Value <> "" Then
MsgBox "PO not valid"
Pobox.Value = ""
End If
End Sub
这将搜索Po.Number,如果找到,它将检查相同行但不同列的大小,最后,如果找到最后两个,则将检查生产件并检查其大于104%就会返回错误
Private Sub Lbox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > 58 Or KeyAscii < 48 Then
KeyAscii = 0
MsgBox ("enter number ")
Lbox.SetFocus
End If
With Worksheets(4).Range("j2:j1048576")
Set c = .Find(Pobox.Value, LookIn:=xlValues)
End With
If Not c Is Nothing Then
With Worksheets(4).Range("s2:s1048576")
Set d = .Find("L", LookIn:=xlValues)
End With
If Not d Is Nothing Then
With Worksheets(4).Range("u2:u1048576")
Set d = .Find("L", LookIn:=xlValues)
End With
If e > 1.04 Then
MsgBox "Too Large "
End If
End If
End If
End Sub
答案 0 :(得分:-1)
我不确定“ L”或“ e”是什么,但除此之外,我将尝试使用循环:
Sub Lbox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > 58 Or KeyAscii < 48 Then
KeyAscii = 0
MsgBox ("enter number ")
Lbox.SetFocus
End If
With ActiveSheet.UsedRange
Set c = .Cells.Find(What:="d", SearchOrder:=xlByRows)
If Not c Is Nothing Then
Do Until c Is Nothing
If c.Column = 10 Then
Set d = .Cells(c.Row).Find(What:="L", SearchOrder:=xlByRows)
If Not d Is Nothing Then
Set d = .FindNext(d)
If Not d Is Nothing Then
Do Until d Is Nothing
Set d = .FindNext(d)
If d.Column = 21 Then
If e > 1.04 Then
MsgBox "Match"
End If
End If
Loop
End If
End If
End If
Set c = .FindNext(c)
Loop
End If
End With
End Sub