我想從一個工作表複製兩個範圍與公式從另一個工作表。隨着「計劃」範圍的內容更改,它們被複制到「Data_Design」工作表上的不同範圍。我有間歇性的代碼,但我無法確定它爲什麼不穩定和可重複。我嘗試了幾種不同的代碼,但無濟於事。當我得到運行時錯誤(1004)時,它在代碼的第一行代碼範圍。任何想法爲什麼1004?VBA Excel將公式從一個工作表複製到另一個工作表
Sub Design_Save()
Dim A, i, D, Ans As Integer
Redo:
D = Application.InputBox("Enter Design Number" & vbNewLine & vbNewLine & "Note: Default value = current stage number", "Design Number Assignment", Worksheets("Job").Cells(10, 3).Value, Type:=1)
For i = 2 To 101 ' Revise the 500 to include all of your values
A = Worksheets("Data_Design").Cells(i, 1).Value
If A = D Then
Ans = MsgBox("Design Number " & D & " already exists." & vbNewLine & vbNewLine & "Overwrite exiting design?", vbYesNo + vbQuestion, "Overwrite Design")
If Ans = vbYes Then
Save_Design (D)
Else
GoTo Redo
End If
Else
Exit Sub
End If
Next i
End Sub
Sub Save_Design(A As Integer)
Dim r1, r2 As Integer
Dim dd1, dd2, dd3, dd4, dd101, dd102, dd103, dd104 As Range
If A = 0 Then
r1 = 1
Else
r1 = A * 100
End If
r2 = r1 + 49
Worksheets("Data_Design").Range(Cells(r1, 2), Cells(r2, 6)).Formula = Worksheets("Schedule").Range("C5:G54").Formula
Worksheets("Data_Design").Range(Cells(r1, 7), Cells(r2, 8)).Formula = Worksheets("Schedule").Range("I5:J54").Formula
Worksheets("Data_Design").Range(Cells(r1, 9), Cells(r2, 23)).Formula = Worksheets("Schedule").Range("L5:Z54").Formula
Worksheets("Data_Design").Range(Cells(r1, 24), Cells(r1, 38)).Formula = Worksheets("Schedule").Range("L3:Z3").Formula
End Sub
試過資格'細胞'? – findwindow