使用用户表单输入输入数据时的“预搜索”列,以防止重复

时间:2018-11-12 14:59:24

标签: excel vba

希望针对我用来输入数据行的用户表单调整以下所述的VBA代码。我想让用户表单显示一个对话框,指出在填写用户表单时此实例中的索赔编号存在于B列中。理想情况下,我希望在填充行数据之前发生这种情况,因此非常感谢提供的任何帮助。

Private Sub AddTable_Click()
Sheets("2018 (1st Party)").Unprotect
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("2018 (1st Party)")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row

'check for a Claim Number'
If Trim(Me.ClaimEntry.Value) = "" Then
Me.ClaimEntry.SetFocus
MsgBox "Please complete the form"
  Exit Sub
End If

'check for a State Value'
If Trim(Me.StateEntry.Value) = "" Then   
  Me.ClaimEntry.SetFocus
  MsgBox "Please complete the form"
  Exit Sub
End If

'Find Revision'
If RevisionYes.Value = True Then
ws.Cells(iRow, 12).Value = "Yes"
ElseIf RevisionNo = True Then
ws.Cells(iRow, 12).Value = "No"
Else
End If

'Find Returned'
If ReturnedYes.Value = True Then
ws.Cells(iRow, 13).Value = "Yes"
ElseIf ReturnedNo = True Then
ws.Cells(iRow, 13).Value = "No"
Else
End If

'Find Party'
If PartyYes.Value = True Then
ws.Cells(iRow, 14).Value = "1st"
ElseIf PartyNo = True Then
ws.Cells(iRow, 14).Value = "3rd"
Else
End If



'copy the data to the database
ws.Cells(iRow, 1).Value = Me.DateEntry.Value
ws.Cells(iRow, 2).Value = Me.ClaimEntry.Value
ws.Cells(iRow, 3).Value = Me.StateEntry.Value
ws.Cells(iRow, 4).Value = Me.INSD_CLMTentry.Value
ws.Cells(iRow, 5).Value = Me.IAFirmEntry.Value
ws.Cells(iRow, 6).Value = Me.IA_Last_NameEntry.Value
ws.Cells(iRow, 7).Value = Me.EstEntry.Value
ws.Cells(iRow, 8).Value = Me.RevisedEntry.Value
ws.Cells(iRow, 15).Value = Me.CommentsEntry.Value

MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data

Me.ClaimEntry.Value = ""
Me.StateEntry.Value = ""
Me.INSD_CLMTentry.Value = ""
Me.IAFirmEntry.Value = ""
Me.IA_Last_NameEntry = ""
Me.EstEntry = ""
Me.RevisedEntry.Value = ""
Me.CommentsEntry.Value = ""
Me.DateEntry.Value = ""

Me.ClaimEntry.SetFocus


Sheets("2018 (1st Party)").Protect
End Sub

0 个答案:

没有答案