更新/编辑数据-VBA Excel

问题描述 投票:0回答:1

enter image description here我浏览了所有页面,似乎找不到答案。任何帮助是极大的赞赏。我已经获得了用于从VBA表单更新工作表中的数据的代码,但是它只是不断在最上面的行上书写,而不编辑特定的行数据。我试图让它编辑正在显示的数据,而不是覆盖顶行数据。任何帮助表示赞赏。我使用的代码是:

Private Sub cmdupdate_Click()

 Dim rowselect As Single
 rowselect = rowselect + 2
 Rows(rowselect).Select

 Cells(rowselect, 1) = Me.txtname.Value
 Cells(rowselect, 2) = Me.txtposition.Value
 Cells(rowselect, 3) = Me.txtassigned.Value
 Cells(rowselect, 4) = Me.cmbsection.Value
 Cells(rowselect, 5) = Me.txtdate.Value
 Cells(rowselect, 7) = Me.txtjoint.Value
 Cells(rowselect, 8) = Me.txtDAS.Value
 Cells(rowselect, 9) = Me.txtDEROS.Value
 Cells(rowselect, 10) = Me.txtDOR.Value
 Cells(rowselect, 11) = Me.txtTAFMSD.Value
 Cells(rowselect, 12) = Me.txtDOS.Value
 Cells(rowselect, 13) = Me.txtPAC.Value
 Cells(rowselect, 14) = Me.ComboTSC.Value
 Cells(rowselect, 15) = Me.txtTSC.Value
 Cells(rowselect, 16) = Me.txtAEF.Value
 Cells(rowselect, 17) = Me.txtPCC.Value
 Cells(rowselect, 18) = Me.txtcourses.Value
 Cells(rowselect, 19) = Me.txtseven.Value
 Cells(rowselect, 20) = Me.txtcle.Value

 End Sub
excel vba edit insert-update
1个回答
0
投票

将以下部分替换为行选择。

Dim rowselect As Integer
rowselect = Range("A" & Rows.count).End(xlUp).Row + 1
'This will give you number of the first blank row below you table in Column A 

' and then all the following will work correctly each time you cilck the button
Cells(rowselect, 1) = Me.txtname.Value
Cells(rowselect, 2) = Me.txtposition.Value
Cells(rowselect, 3) = Me.txtassigned.Value ' and so on
© www.soinside.com 2019 - 2024. All rights reserved.