Sub hello()
Dim Z As Integer
Dim X As Integer
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim E As Integer
Dim G As Integer
Dim H As Integer
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim W As Integer
Dim Y As Integer
Dim M As Integer
Dim Q As Integer
Dim L As Integer
Dim Z1 As Integer
Dim Z2 As Integer
Dim Z3 As Integer
Dim G1 As Integer
Dim G2 As Integer
Dim G3 As Integer
Dim G4 As Integer
Dim G5 As Integer
Dim G6 As Integer
Dim Z4 As Integer
Dim E1 As Integer
Dim E2 As Integer
Dim E3 As Integer
Dim E4 As Integer
Dim E5 As Integer
Dim E6 As Integer
Dim E7 As Integer
Dim E8 As Integer
Dim E9 As Integer
Dim E10 As Integer
For G2 = 7 To 17
Cells("2", "CS") = 0
Cells("2", "CT") = 0
Cells("2", "CU") = 0
Cells("2", "CV") = 0
Cells("2", "CW") = 0
Cells("2", "CX") = 0
Cells("2", "CY") = 0
Cells("2", "CZ") = 0
Cells("2", "DA") = 0
Cells("2", "DB") = 0
If G2 = 7 Then
Z3 = Cells("3", "DC").Value
Z2 = G2
End If
If G2 = 8 Then
Z3 = Cells("3", "DD").Value
Z2 = G2
End If
If G2 = 9 Then
Z3 = Cells("3", "DE").Value
Z2 = G2
End If
If G2 = 10 Then
Z3 = Cells("3", "DF").Value
Z2 = G2
End If
If G2 = 11 Then
Z3 = Cells("3", "DG").Value
Z2 = G2
End If
If G2 = 12 Then
Z3 = Cells("3", "DH").Value
Z2 = G2
End If
If G2 = 13 Then
Z3 = Cells("3", "DI").Value
Z2 = G2
End If
If G2 = 14 Then
Z3 = Cells("3", "DJ").Value
Z2 = G2
End If
If G2 = 15 Then
Z3 = Cells("3", "DK").Value
Z2 = G2
End If
If G2 = 16 Then
Z3 = Cells("3", "DL").Value
Z2 = G2
End If
If G2 = 17 Then
Z3 = Cells("3", "DM").Value
Z2 = G2
End If
For E = Z3 To Range("A65536").End(xlUp).Row
Debug.Print E
If Cells(E, "CS") > 0 Then 程式到這句出錯 錯誤1004 。前面加debug.print E 還是不行。E的值等于0,怎么改??
Cells(E, "CS") = 0
uj5u.com熱心網友回復:
E等于0,是因為Z3的值為0唄。Z3等于0,是因為在你的“For G2 = 7 To 17”中,前面的賦值陳述句把Z3賦值為0。
它報錯時,點“除錯”,然后看看G2的值是多少、再找對應的Z3賦值陳述句,它取的是哪個單元格的值;
再到“當前活動作業表”中,看看對應的單元格是不是沒有資料,或值為0。
你要注意,你的Z3賦值陳述句:Z3 = Cells(XX, XXXX).Value
這都沒有“明確指定作業表”,那么它就是讀取的“當前作業簿的當前活動作業表”,
你在作業簿“選定的作業表”不正確,都會造成執行的錯誤。
這樣的VBA代碼,寫得太差勁了!
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/72131.html
標籤:VBA
上一篇:Inet POST提交的問題
下一篇:拖動無嚦蟣韱蜛PI
