用户表单自动填写ID号并在前面减去单词

时间:2018-06-25 22:53:47

标签: vba userform

我已经创建了一个简单的用户窗体,可以在电子表格的“工具”列表中输入新设备的详细信息,除了一个小东西,即“新工具ID”,该窗体可以正常工作。

基本上,我需要做的是一旦打开表单/需要创建新的工具ID,它可能是Alfa数字字符集,例如AA-01234,AA-01235,AA-01236等

此外,还有一种方法可以在MsgBox中发布新添加的工具ID以及MsgBox“一条记录已添加到客户列表。新客户ID为”

我创建此应用程序的所有尝试均失败并导致错误,由于我是VBA的新手,并且到目前为止从未使用过它,所以我真的无法弄清楚。

这是我的代码,客户ID是TextBox1。

预先感谢 [![在此处输入图片描述] [1]] [1] 这是对我有用的代码,但不会将其删除。

Private Sub CommandButton1_Click()
If Application.WorksheetFunction.CountIf(Range("A:A"), Me.TextBox1) > 0 Then
If MsgBox("Tool Name Already Exists.Do you want to continue?", vbQuestion + vbYesNo) <> vbYes Then
Exit Sub
End If
End If

If TextBox1.Value = "" Or TextBox2.Value = "" Or TextBox4.Value = "" Or TextBox5.Value = "" Or TextBox6.Value = "" Then
If MsgBox("Form is not complete. Do you want to continue?", vbQuestion + vbYesNo) <> vbYes Then
Exit Sub
End If
End If
Dim ssheet As Worksheet

Set ssheet = ThisWorkbook.Sheets("2018")
nr = ssheet.Cells(Rows.Count, 1).End(xlUp).Row + 1

ssheet.Cells(nr, 1) = TextBox1.Value
ssheet.Cells(nr, 2) = TextBox2.Value
ssheet.Cells(nr, 3) = TextBox3.Value
ssheet.Cells(nr, 4) = TextBox4.Value
ssheet.Cells(nr, 5) = TextBox5.Value
ssheet.Cells(nr, 6) = TextBox6.Value
ssheet.Cells(nr, 7) = TextBox7.Value

Call resetForm

End Sub

Sub resetForm()
TextBox1.Value = ""
TextBox2.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
Data_Entry.TextBox1.SetFocus

End Sub
Private Sub CommandButton2_Click()
TextBox1.Value = ""
TextBox2.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
Data_Entry.TextBox1.SetFocus
End Sub

Private Sub UserForm_Initialize()

Me.TextBox1 = Application.WorksheetFunction.Max(Range("A:A")) + 1

Me.TextBox3 = Date

End Sub
    Private Sub UserForm_Initialize()
    Me.TextBox1 = Application.WorksheetFunction.Max(Range("A:A")) + 1
    Me.TextBox3 = Date
    End Sub


[1]: https://i.stack.imgur.com/yQABC.jpg

0 个答案:

没有答案