【发布时间】:2020-03-12 02:20:06
【问题描述】:
我已经尝试了几天来获得一个在 excel VBA 表单中工作的下一步按钮。我有一个包含多个项目的表单,包括一些组合框。我反复尝试让代码正常工作,这样我就可以添加下一个项目按钮和上一个项目按钮。我希望这些按钮搜索表格数据并显示上一组数据和下一组数据。最终,一旦按钮工作,就可以编辑这些。上一个按钮将我带到第一组数据,但不会循环,下一个按钮在我的行名中出现对象错误(txt.name.text = cells(currentrow,1) 代码。获取这些按钮的任何帮助或帮助工作将不胜感激。
Private Sub cmdnext_Click()
Dim lastrow As Long
Dim currentrow As Long
lastrow = Sheet1.Cells(Rows.Count, 2).End(xlUp).Row
currentrow = currentrow + 2
txtname = Cells(currentrow, 1)
txtposition = Cells(currentrow, 2)
txtassigned = Cells(currentrow, 3)
cmbsection.Text = Cells(currentrow, 4)
txtdate.Text = Cells(currentrow, 5)
txtjoint = Cells(currentrow, 7)
txtDAS.Text = Cells(currentrow, 8)
txtDEROS.Text = Cells(currentrow, 9)
txtDOR.Text = Cells(currentrow, 10)
txtTAFMSD.Text = Cells(currentrow, 11)
txtDOS.Text = Cells(currentrow, 12)
txtPAC.Text = Cells(currentrow, 13)
ComboTSC.Text = Cells(currentrow, 14)
txtTSC.Text = Cells(currentrow, 15)
txtAEF.Text = Cells(currentrow, 16)
txtPCC.Text = Cells(currentrow, 17)
txtcourses.Text = Cells(currentrow, 18)
txtseven.Text = Cells(currentrow, 19)
txtcle.Text = Cells(currentrow, 20)
If currentrow = lastrow Then
MsgBox "Why wont this work"
End If
End Sub
Private Sub CommandButton6_Click()
Dim lastrow As Long
Dim currentrow As Long
If lastrow = currentrow Then
MsgBox "this doesn work yet"
End If
currentrow = currentrow - 2
txtname.Text = Cells(currentrow, 1)
txtposition = Cells(currentrow, 2)
txtassigned = Cells(currentrow, 3)
cmbsection.Text = Cells(currentrow, 4)
txtdate.Text = Cells(currentrow, 5)
txtjoint = Cells(currentrow, 7)
txtDAS.Text = Cells(currentrow, 8)
txtDEROS.Text = Cells(currentrow, 9)
txtDOR.Text = Cells(currentrow, 10)
txtTAFMSD.Text = Cells(currentrow, 11)
txtDOS.Text = Cells(currentrow, 12)
txtPAC.Text = Cells(currentrow, 13)
ComboTSC.Text = Cells(currentrow, 14)
txtTSC.Text = Cells(currentrow, 15)
txtAEF.Text = Cells(currentrow, 16)
txtPCC.Text = Cells(currentrow, 17)
txtcourses.Text = Cells(currentrow, 18)
txtseven.Text = Cells(currentrow, 19)
txtcle.Text = Cells(currentrow, 20)
End Sub
【问题讨论】: