1)我在 VBA 中创建了一个表单,并且我已经连接到第一张工作表,当我单击按钮时,表单会弹出以输入数据,但我想要的是,我想在第一张工作表中分配一个按钮,然后当我点击按钮时,表单应该出现,当我将数据插入表单时,它应该出现在第二张表中。
2)我只在工作表中插入四行数据,完成后如果想修改特定列或特定行的数据,我们该怎么做,我需要有人建议我,我也请你发给我代码如何修改。
3)如果我想输入新数据,我还要求您将代码发送给我以清除工作表。
如果有人在这 3 点上帮助我,我会很高兴。
Private Sub cmdAdd_Click()
Dim i As Integer
'position cursor in the correct cell B9.
Range("B9:P40").Select
i = 1 'set as the first ID
'validate first four controls have been entered...
If Me.txtFName.Text = Empty Then 'Firstname
MsgBox "Please enter firstname.", vbExclamation
Me.txtFName.SetFocus 'position cursor to try again
Exit Sub 'terminate here - why continue?
End If
If Me.txtSName.Text = Empty Then 'Surname
MsgBox "Please enter surname.", vbExclamation
Me.txtSName.SetFocus 'position cursor to try again
Exit Sub 'terminate here - why continue?
End If
If Me.txtFuName.Text = Empty Then 'FullName
MsgBox "Please enter fullname.", vbExclamation
Me.txtFuName.SetFocus 'position cursor to try again
Exit Sub 'terminate here - why continue?
End If
If Me.txtDName.Text = Empty Then 'Designation
MsgBox "Please enter Designation.", vbExclamation
Me.txtDName.SetFocus 'position cursor to try again
Exit Sub 'terminate here - why continue?
End If
'if all the above are false (OK) then carry on.
'check to see the next available blank row start at cell B9...
Do Until ActiveCell.Value = Empty
ActiveCell.Offset(1, 0).Select 'move down 1 row
i = i + 1 'keep a count of the ID for later use
Loop
'Populate the new data values into the 'Data' worksheet.
ActiveCell.Value = i 'Next ID number
ActiveCell.Offset(0, 1).Value = Me.txtFName.Text 'set col B
ActiveCell.Offset(0, 2).Value = Me.txtSName.Text 'set col C
ActiveCell.Offset(0, 3).Value = Me.txtFuName.Text 'set col D
ActiveCell.Offset(0, 4).Value = Me.txtDName.Text 'set col E
'Clear down the values ready for the next record entry...
Me.txtFName.Text = Empty
Me.txtSName.Text = Empty
Me.txtFuName.Text = Empty
Me.txtDName.Text = Empty
Me.txtFName.SetFocus 'positions the cursor for next record entry
End Sub
Private Sub cmdClose_Click()
'Close the form (itself)
Unload Me
End Sub