我正在使用&#34; Save&#34;和&#34;改变&#34;用于添加/更改范围A中的订单号的按钮:A。如果我输入新的订单号(&#34;保存&#34;按钮),但是如果我想要更改已经存在于范围A中的旧订单号(&#34;更改&#34;按钮),则它正在工作:A < / p>
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, "d.m.yyyy")
Cells(sonsat, 5) = Format(TextBox5, "d.m.yyyy")
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:A范围内只存在一次,我可以更改订单号。这些订单号由用户通过文本框(VBA表单)输入