[VBA ] 應用程式或物件定義上的錯誤

看板Visual_Basic作者 (菩提王子)時間12年前 (2012/04/03 14:44), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
程式碼如下 Sub hulk() Dim Title, Default, MyValue Dim i_1, i_2, a_1, a_2, a_3 As Integer Message_1 = "買CALL幾口?請輸入三口以下(包含三口)" ' 設定提示訊息。 Message_2 = "賣CALL幾口?請輸入三口以下(包含三口)" Message_3 = "買PUT幾口?請輸入三口以下(包含三口)" Message_4 = "賣PUT幾口?請輸入三口以下(包含三口)" Title = "InputBox Demo" ' 設定標題。 Default = "0" ' 設定預設值。 ' 顯示訊息、標題及預設值。 a = InputBox(Message_1, Title, Default) b = InputBox(Message_2, Title, Default) C = InputBox(Message_3, Title, Default) D = InputBox(Message_4, Title, Default) '把a轉成可以運算的型態 a_1 = CDbl(a) b_1 = CDbl(b) c_1 = CDbl(C) d_1 = CDbl(D) MsgBox "買CALL幾口?" & a_1 MsgBox "賣CALL幾口?" & b_1 MsgBox "買PUT幾口?" & c_1 MsgBox "賣PUT幾口?" & d_1 j = 1 If a_1 > 0 Then For i_1 = 1 To a_1 message_5 = "買第" & i_1 & "口CALL的履約價 ?" a_2 = InputBox(message_5, Title, Default) a_3 = CDbl(a_2) For i_2 = 4 To 19 If Sheets("sheet1").Cells(4, i_2).Value = a_3 Then Worksheets("sheet1").Range(Cells(4, i_2), Cells(335, i_2)).Select Selection.Copy Worksheets("sheet5").Range(Cells(1, j), Cells(332, j)).Select ActiveSheet.Paste End If Next i_2 j = j + 1 Next i_1 End If End Sub 想要問的是這一行 Worksheets("sheet1").Range(Cells(4, i_2), Cells(335, i_2)).Select Selection.Copy 當巨集在執行的時候會發生標題上所說的錯誤! 懇請版上大大跟我說一下哪邊出問題了! 感激不盡ORZ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.85.59.207

04/04 06:56, , 1F
Cells前面加上 Worksheets("sheet1"). 試試
04/04 06:56, 1F

04/05 09:00, , 2F
謝謝,立馬試試!
04/05 09:00, 2F

04/05 18:04, , 3F
C大可以執行了! 感激不盡。ORZ
04/05 18:04, 3F
文章代碼(AID): #1FUfmzsg (Visual_Basic)