【发布时间】:2020-07-30 19:04:51
【问题描述】:
我不断收到以下行的“下标超出范围”错误:Worksheets("Sheet3").Range("A4").Copy
我是 VBA 新手,所以我确定我缺少一些东西 - 你有什么意见吗?
此代码的基础是将用户表单中的数据输入到一个工作表中,然后将该行代码复制到第一个空行中的另一个工作表中。
提前谢谢你!!
Private Sub EnterButton_Click()
Application.CutCopyMode = True
'Determine emptyRow
emptyrow = WorksheetFunction.CountA(Range("A:A")) + 1
Sheet3.Activate
'Transfer information
Cells(emptyrow, 1).Value = textbox1.Value
Cells(emptyrow, 2).Value = textbox2.Value
Cells(emptyrow, 3).Value = textbox3.Value
Cells(emptyrow, 4).Value = textbox4.Value
Cells(emptyrow, 5).Value = textbox5.Value
Cells(emptyrow, 6).Value = textbox6.Value
Cells(emptyrow, 7).Value = textbox7.Value
Cells(emptyrow, 8).Value = textbox8.Value
Cells(emptyrow, 9).Value = textbox9.Value
Cells(emptyrow, 11).Value = textbox11.Value
Cells(emptyrow, 12).Value = textbox12.Value
Cells(emptyrow, 13).Value = textbox13.Value
Cells(emptyrow, 14).Value = textbox14.Value
Cells(emptyrow, 17).Value = textbox17.Value
Cells(emptyrow, 18).Value = textbox18.Value
Cells(emptyrow, 19).Value = textbox19.Value
Cells(emptyrow, 20).Value = textbox20.Value
Cells(emptyrow, 21).Value = textbox21.Value
Cells(emptyrow, 25).Value = textbox25.Value
Cells(emptyrow, 26).Value = textbox26.Value
Cells(emptyrow, 27).Value = textbox27.Value
Cells(emptyrow, 28).Value = textbox28.Value
Cells(emptyrow, 29).Value = textbox29.Value
Cells(emptyrow, 33).Value = textbox33.Value
Cells(emptyrow, 34).Value = textbox34.Value
Cells(emptyrow, 35).Value = textbox35.Value
Cells(emptyrow, 36).Value = textbox36.Value
Cells(emptyrow, 37).Value = textbox37.Value
Cells(emptyrow, 41).Value = textbox41.Value
Cells(emptyrow, 42).Value = textbox42.Value
Cells(emptyrow, 43).Value = textbox43.Value
Cells(emptyrow, 44).Value = textbox44.Value
Cells(emptyrow, 45).Value = textbox45.Value
Worksheets("Sheet3").Range("A4").Copy
Worksheets("Sheet6").Range("A" & Rows.count_.End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteFormulas
Application.CutCopyMode = False
End Sub
【问题讨论】:
-
这意味着活动工作簿没有名为“Sheet3”的工作表。
标签: excel vba userform subscript