编辑VBA用户表单脚本

时间:2018-04-04 14:36:18

标签: excel-vba userform vba excel

Worksheets(whichSheet).Activate
Dim lastrow
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

lastrow = lastrow + 1
Cells(lastrow, 1) = TextBox1
If Application.WorksheetFunction.CountIf(Range("A2:A" & lastrow), Cells(lastrow, 1)) > 1 Then
MsgBox "Duplicate data! Only unique IDs allowed", vbCritical, "Remove Data"
Cells(lastrow, 1) = ""
ElseIf Application.WorksheetFunction.CountIf(Range("A2:A" & lastrow), Cells(lastrow, 1)) = 1 Then
answer = MsgBox("Are you sure you want to add the record?", vbYesNo + vbQuestion, "Add Record")
If answer = vbYes Then
Cells(lastrow, 1) = TextBox1.Text
Cells(lastrow, 2) = TextBox2.Text
Cells(lastrow, 3) = TextBox3.Value
Cells(lastrow, 4) = TextBox4.Text
Cells(lastrow, 5) = TextBox5.Text
End If
End If

对于上面的代码,我只想摆脱重复ID的ID限制。任何帮助都将不胜感激。

0 个答案:

没有答案