我正在寻求实现将数据添加到列表的用户窗体。该用户窗体将数据正确输入到正确的列中。我想添加数据,然后移到下一行,我可以在其中输入另一行数据。但是,当我单击第二组的命令按钮时,它将替换同一行,而不是移至下方的那一行。我已附加我的代码,我相信“ iRow”方程式有问题。我是VBA的新手,可以使用一些帮助。预先感谢。
Private Sub cmd_add_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Program Detail Input")
iRow = ws.Cells.Find(What:=” * ”, SearchOrder:=xlRows, Searchdirection:=xlPrevious, LookIn:=xlValues).Row + 1
iRow = iRow + 1
If Trim(Me.txtprgrm) = "" Then
MsgBox "Please enter a Program Name"
Exit Sub
End If
If Trim(Me.cboRegion) = "" Then
MsgBox "Please enter a region"
Exit Sub
End If
With ws
ws.Cells(iRow, 3).Value = Me.txtprgrm.Value
ws.Cells(iRow, 4).Value = Me.cboRegion.Value
ws.Cells(iRow, 5).Value = Me.cboStatus.Value
ws.Cells(iRow, 6).Value = Me.TextBox1.Value
End With
Me.txtprgrm.Value = ""
Me.cboRegion.Value = ""
Me.cboStatus.Value = ""
Me.txtprgrm.SetFocus
End Sub