作为非专业人士,但为了研究如何在excel中加快数据输入,我设计了一个Excel用户窗体,其中每个“ Actor”和“ Paxs”文本框均带有“ split row and columns”。在最初输入的情况下,输入内容不错,但是如果重复输入,则信息将覆盖最近的信息。我不知道如何调整这种覆盖。我想念那里的东西吗?请告知。
Private Sub cmdIn_Click()
Dim RowCnt As Long
Dim Actors As Variant
Dim ColNum1 As Variant
Dim j As Integer
Dim Paxs As Variant
Dim ColNum2 As Variant
Dim k As Integer
Dim ws As Worksheet
Set ws = Worksheets("ActPaxs")
RowCnt = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
RowCnt = 2
Actors = Split(Me.TxtActors.Value, vbCrLf)
For Each r In Actors
j = 1
ColNum1 = Split(r, ", ")
For Each c In ColNum1
ws.Cells(RowCnt, j).Value = c
j = j + 1
Next c
RowCnt = RowCnt + 1
Next r
RowCnt = 2
Paxs = Split(Me.TxtPaxs.Value, vbCrLf)
For Each p In Paxs
k = 4
ColNum2 = Split(p, ", ")
For Each q In ColNum2
ws.Cells(RowCnt, k).Value = q
k = k + 1
Next q
RowCnt = RowCnt + 1
Next p
TxtActors.Text = ""
TxtPaxs.Text = ""
End Sub
如何重复相同的代码以添加更多数据而不覆盖现有数据?
答案 0 :(得分:0)
RowCnt = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
RowCnt = 2
删除第二个硬编码到行2的实例,第一个实例检测到最后使用的行并偏移1
编辑:在代码中,您还有另一个RowCnt = 2实例,请将其删除。