我创建了一个表单并且工作正常。这是我的表格
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
在我的excelsheet中已经输入了该人的唯一ID。当通过此表单输入数据时,它应该搜索该特定ID以及要输入的数据的面前。
我该怎么做?
提前致谢
答案 0 :(得分:0)
而不是
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
选择最后一个非空行下面的行,试试这个:
iRow = WorksheetFunction.Match(personID, Columns("A"), False)
您没有解释此人ID是什么......也许Me.txtPerson.Value
?无论如何,请在适当时替换personID
。