我正在尝试将所有数据保存在同一个文件中,因为它在共享网络上工作。由于某种原因,一旦通过UserForm输入数据并在工作表中对其进行编译,这些数据就不会全部编译到我的原始工作表中,而是会编译到.xlsx
中的新工作表中。我可以添加一些地方,使其保留在同一文件中吗?
我连接到命令按钮的代码如下:
Private Sub CommandButton1_Click()
Dim rw As Integer
Dim ws As Worksheet
Dim emptyRow As Long
'Make Sheet2 active
Sheet2.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
Cells(emptyRow, 1).Value = Me.TextBox1.Value
Cells(emptyRow, 2).Value = Me.TextBox2.Value
Cells(emptyRow, 3).Value = Me.TextBox3.Value
Cells(emptyRow, 4).Value = Me.TextBox4.Value
Cells(emptyRow, 5).Value = Me.TextBox5.Value
Cells(emptyRow, 6).Value = Me.TextBox6.Value
End Sub
答案 0 :(得分:0)
类似这样的东西:
Private Sub CommandButton1_Click()
Dim rw As Range
Set rw = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1,0).EntireRow
With rw
.Cells(1).Value = Me.TextBox1.Value
.Cells(2).Value = Me.TextBox2.Value
.Cells(3).Value = Me.TextBox3.Value
.Cells(4).Value = Me.TextBox4.Value
.Cells(5).Value = Me.TextBox5.Value
.Cells(6).Value = Me.TextBox6.Value
End With
End Sub