开发者

In Excel form when the data is entered through the form it should search that particular ID already entered in the sheet

I have created a form and it is working fine. Here is my form

 Private Sub cmdAdd_Click()
Dim iRow As Long
Dim iAction As Long 
Dim iPriority As Long
Dim ws As Worksheet
Set ws = Worksheets("PlanningActions")
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
If Trim(Me.txtAction.Value) = "" Then
Me.txtAction.SetFocus
MsgBox "Please enter an Action"
Exit Sub
End If


ws.Cells(iRow, 1).Value = Me.txtAction.Value
ws.Cells(iRow, 2).Value = Me.txtTopic.Value
ws.Cells(iRow, 3).Value = Me.txtPerson.Value
ws.Cells(iRow, 4).Value = Me.txtLocation.Value
ws.Cells(iRow, 5).Value = Me.txtDate.Value
ws.Cells(iRow, 6).Value = Me.txtContact.Value
ws.Cells(iRow, 7).Value = Me.cboPriority.Value
ws.Cells(iRow, 8).Value = Me.cboPriority.List(iPriority, 1)
Me.txtAction.Value = ""
Me.txtTopic.Value = ""
Me.txtPerson.Value = ""
Me.txtLocation.Value = ""
Me.txtContact.Value = ""
Me.cboPriority.Value = ""
Me.txtDate.Value = ""
Me.txtAction.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub
Private Sub UserForm_Initialize()
Dim cPri As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")
For Each cPri In ws.Range("Priority")
With Me.cboPriority
.AddItem cPri.Value
.List(.ListCount - 1, 0) = cPri.Offset(0, 1).Value
End With
Next cPri
Me.txtAction.Value = ""
Me.txtTopic.Value = ""
Me.txtPerson.Value = ""
Me.txtLocation.Value = ""
Me.txtDate.Value = ""
Me.txtContact.Value = ""
Me.cboPriority.Value = ""
Me.txtAction.SetFocus
End Sub

In my excelsheet already unique ID's of the person has been entered. when the data is entered through this form it should search that particular ID and infront of that data开发者_JS百科 to be entered.

How do i do that?

Thanks in advance


Instead of

iRow = ws.Cells(Rows.Count, 1) _
       .End(xlUp).Offset(1, 0).Row

which selects the row below the last non-empty row, try this:

iRow = WorksheetFunction.Match(personID, Columns("A"), False)

You don't explain what the person ID is... maybe Me.txtPerson.Value? Anyway, replace personID as appropriate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜