由于运行时错误438,宏将不会复制值

时间:2019-09-27 11:25:22

标签: excel vba

我正在尝试创建一个宏,该宏会将数据从一个表单Form复制到另一个表单Log。我很快想出了一些我认为可以解决问题的代码,但是在复制值时,出现了“运行时错误438”,并且在网上搜索后,我仍然无法理解。 >

    Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Log")

'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1


'copy the data to the log sheet

With ws

  .Cells(iRow, 1).Value = Worksheets("Form").Value(D3)            'this is where runtime error occurs.
  .Cells(iRow, 2).Value = Worksheets("Form").Value(D5)
  .Cells(iRow, 3).Value = Worksheets("Form").Value(D10)
  .Cells(iRow, 4).Value = Worksheets("Form").Value(D12)

End With

'clear the data
Worksheets("Form").Value(D3) = ""
Worksheets("Form").Value(D5) = ""
Worksheets("Form").Value(D10) = ""
Worksheets("Form").Value(D12) = ""

End Sub

我只是想知道是否有人理解该错误,该错误如何应用于我的代码,并且可以让我快速了解为什么发生此错误?这将不胜感激。谢谢。

0 个答案:

没有答案