VBA表格 – 如果在范围内只存在一次,可能会改变文本框的值

我正在使用“保存”和“更改”button来添加/更改范围A中的订单号:A。 如果我要更改已存在于范围A中的旧订单号(“更改”button),则input新的订单号(“保存”button),但不起作用; A

Private Sub CommandButton2_Click() 'Change Button Dim sonsat As Long If ListBox1.ListIndex = -1 Then MsgBox "Select ", vbExclamation Exit Sub End If Sheets("orders").Range("A:A").Find(ListBox1.Text).Activate sonsat = ActiveCell.Row If Not Columns(1).Find(Me.TextBox1.Value, , , xlWhole, , , False) Is Nothing Then MsgBox Me.TextBox1.Value & " Already used ", , "Same number" Cancel = True Exit Sub End If Cells(sonsat, 1) = TextBox1 Cells(sonsat, 2) = TextBox2 Cells(sonsat, 3) = CDbl(TextBox3) Cells(sonsat, 4) = Format(TextBox4, "dmyyyy") Cells(sonsat, 5) = Format(TextBox5, "dmyyyy") Cells(sonsat, 6) = CDbl(TextBox6) Call Main 'Progress Bar MsgBox "Changed" ListBox1.List = Sheets("orders").Range("a2:l" & [a65536].End(3).Row).Value 'For refresh listbox End Sub 

我需要更新这个代码,如果在范围A中只存在一次,可以允许我更改订单号。 这些订单号由用户通过文本框(V​​BA表格)