自动将用户表单数据转移到下一个空白行

时间:2018-08-23 05:53:56

标签: excel vba userform

我试图找出我要去哪里,但没有成功。

当我单击 submit 按钮时,我能够从用户窗体中捕获数据,并且该数据被传输到Excel工作表的第一行。但是,当我清除用户窗体并尝试输入新数据并单击 submit 按钮时,它会将新数据传输到旧数据(第一行)上,不会自动移动到第二行。

我已经检查了所有可能性,请在我在代码中做错的地方提供帮助。

下面是“提交”按钮的代码。

Private Sub btnsave_Click()


Dim WB As Workbook
Dim ssheet as Worksheet

Set WB = Workbooks.Open("C:\Users\Gateways.xlsx")
Set ssheet = WB.Worksheets("Proc")

Dim nr As Integer
nr = ssheet.Cells(Rows.Count, 1).End(xlUp).Row + 1 'keep a count of the ID for later use Loop

'Populate the new data values into the 'Data' worksheet 'Next ID number

ssheet.Cells(nr, 3) = Me.cmbls
ssheet.Cells(nr, 4) = Me.tbProject
ssheet.Cells(nr, 5) = Me.cmbbase
 If cmbbase.Value = "" Then
 
      MsgBox "You must complete base", vbCritical
      Exit Sub
 
  End If

ssheet.Cells(nr, 6) = Me.tbenovia
  If tbenovia.Value = "" Then
 
      MsgBox "You must complete Enovia no", vbCritical
      Exit Sub
 
  End If

ssheet.Cells(nr, 7) = Me.tbaxalant
ssheet.Cells(nr, 8) = Me.tbmaterial
ssheet.Cells(nr, 9) = Me.tbpart
ssheet.Cells(nr, 10) = Me.tbrequest
ssheet.Cells(nr, 11) = Me.cmbtask1
ssheet.Cells(nr, 12) = Me.cmbdetail1
ssheet.Cells(nr, 13) = Me.tbdetail2
ssheet.Cells(nr, 14) = Me.tbtools
ssheet.Cells(nr, 18) = Me.cmblocation
ssheet.Cells(nr, 19) = Me.tbadd
ssheet.Cells(nr, 15) = Me.cmburgent
ssheet.Cells(nr, 2) = CDate(DTPicker1)
ssheet.Cells(nr, 17) = CDate(DTPicker2)
ssheet.Cells(nr, 20) = CDate(DTPicker3)
If radioyes = True Then
    ssheet.Cells(nr, 16) = "Yes"
Else
    ssheet.Cells(nr, 16) = "No"
End If
ActiveWorkbook.Save

End Sub

0 个答案:

没有答案