将文本框中的值写入单行

我有一些文本框和一个button,单击时,将文本框中的值写入一行,这里是一个截图:

在这里输入图像说明

这里是代码:

Function theLastRow() As Long Dim lastRow As Long lastRow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row theLastRow = lastRow End Function Private Sub button1_Click() Sheet2.Cells(theLastRow + 1, 5).Value = Comment.Value 'cant be left empty If (name1.Value <> "" And name2.Value <> "" And szsz.Value <> "" And Sum.Value <> "") Then Sheet2.Cells(theLastRow + 1, 1).Value = name1.Value Sheet2.Cells(theLastRow + 1, 2).Value = name2.Value Sheet2.Cells(theLastRow + 1, 3).Value = szsz.Value Sheet2.Cells(theLastRow + 1, 4).Value = Sum.Value End If End Sub 

它几乎适用于它应该如何,但不完全是:

在这里输入图像说明

Name2szsz和总是低一行,这是什么问题?

根据我上面的评论,试试这个。

 Private Sub button1_Click() Dim LastRow As Long LastRow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row Sheet2.Cells(LastRow + 1, 5).Value = Comment.Value 'cant be left empty If (name1.Value <> "" And name2.Value <> "" And szsz.Value <> "" And Sum.Value <> "") Then Sheet2.Cells(LastRow + 1, 1).Value = name1.Value Sheet2.Cells(LastRow + 1, 2).Value = name2.Value Sheet2.Cells(LastRow + 1, 3).Value = szsz.Value Sheet2.Cells(LastRow + 1, 4).Value = Sum.Value End If End Sub