0

我有一个用户表单,它将从字段提交数据到列 A、B 和 C,但我需要它向下移动并在每次用户点击提交时填写下一个空行。

这是我到目前为止所拥有的,我不知道我会投入什么来制作它,所以它会从 A2/B2/C2 变为 A3/B3/C3 等。

Private Sub Submit_Click()
   Dim LastRow As Object

   Set LastRow = Sheet1.Range("a65536").End(xlUp)

   Sheet1.Range("A2").Value = MatchNum.Text
   Sheet1.Range("B2").Value = TeamNum.Text
   Sheet1.Range("C2").Value = AllianceTeamNum.Text

   MsgBox "One record written to Sheet1"

End Sub

我是 Visual Basic 的完整初学者(大约 1 小时的经验),如果解决方案尽可能简单,那就太好了。任何帮助将非常感激!

4

2 回答 2

3

试试下面的代码:

Private Sub Submit_Click()
    With Sheet1
        .Select

        Dim LastRow As Long
        LastRow = .Range("A65536").End(xlUp).Row + 1

        .Range("A" & LastRow).Value = MatchNum.Text
        .Range("B" & LastRow).Value = TeamNum.Text
        .Range("C" & LastRow).Value = AllianceTeamNum.Text

    End With
    MsgBox "One record written to Sheet1"

End Sub
于 2013-03-13T04:25:45.717 回答
-1

尝试这个:

Dim start As Integer

Private Sub CommandButton1_Click()

   Dim LastRow As Object

   Set LastRow = Sheet1.Range("a65536").End(xlUp)

   Sheet1.Range("A" & start).Value = "a"
   Sheet1.Range("B" & start).Value = "b"
   Sheet1.Range("C" & start).Value = "c"

   MsgBox "One record written to Sheet1"

   start = start + 1

End Sub

Private Sub UserForm_Initialize()
   start = 2
End Sub
于 2013-03-13T02:15:47.927 回答