运行时错误“1004”:应用程序定义或对象定义的错误。 (复制和粘贴结果)
我试图把结果从表a到相应的不同表。
Sub update() Dim cell As String, sheet As String, rcdate As String, row As Integer row = 2 ThisWorkbook.Sheets("Auto Generate V2").Activate cell = CStr(ThisWorkbook.Sheets("Auto Generate V2").Cells(row, 10).value) Do While cell <> "" sheet = Left(cell, 10) rcdate = Right(cell, 3) ThisWorkbook.Sheets(sheet).Activate ThisWorkbook.Sheets(sheet).Range(rcdate).value = ThisWorkbook.Sheets("Auto Generate V2").Cells(row, 5).value row = row + 1 cell = CStr(ThisWorkbook.Sheets("Auto Generate V2").Cells(row, 10).value) Loop End Sub
错误是在ThisWorkbook.Sheets(表).Range(acdate).value = ThisWorkbook.Sheets(“Auto Generate V2”)。Cells(row,5).value如何解决
不必要的Worksheet.Activate方法无疑会造成不稳定的环境。 我已经修改了你的例程来消除对.ActiveSheet的依赖。
Sub update() Dim cell As String, sht As String, rcDate As String, rw As Long rw = 2 With ThisWorkbook.Worksheets("Auto Generate V2") cell = Trim(CStr(.Cells(rw, 10).Value)) Do While cell <> "" sht = Left(cell, 10) rcDate = Right(cell, 3) 'Debug.Print .Parent.Worksheets(sht).Range(rcDate).Address(external:=True) .Parent.Worksheets(sht).Range(rcDate) = .Cells(rw, 5).Value rw = rw + 1 cell = Trim(CStr(.Cells(rw, 10).Value)) Loop End With End Sub
如果仍有问题,请考虑closures所有设备并重新启动电脑。 在一个子开发过程中发生的一系列崩溃可能导致一个潜在的不稳定的编译器环境。 不止一次简单的机器重启已经解决了一个未知的问题。