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 ThenZ3 = Cells("3", "DC").ValueZ2 = G2End If
If G2 = 8 ThenZ3 = Cells("3", "DD").ValueZ2 = G2End If
If G2 = 9 ThenZ3 = Cells("3", "DE").ValueZ2 = G2End If
If G2 = 10 ThenZ3 = Cells("3", "DF").ValueZ2 = G2End If
If G2 = 11 ThenZ3 = Cells("3", "DG").ValueZ2 = G2End If
If G2 = 12 ThenZ3 = Cells("3", "DH").ValueZ2 = G2End If
If G2 = 13 ThenZ3 = Cells("3", "DI").ValueZ2 = G2End If
If G2 = 14 ThenZ3 = Cells("3", "DJ").ValueZ2 = G2End If
If G2 = 15 ThenZ3 = Cells("3", "DK").ValueZ2 = G2End If
If G2 = 16 ThenZ3 = Cells("3", "DL").ValueZ2 = G2End If
If G2 = 17 ThenZ3 = Cells("3", "DM").ValueZ2 = G2End If
For E = Z3 To Range("A65536").End(xlUp).Row
Debug.Print EIf Cells(E, "CS") > 0 Then  程序到这句出错 错误1004 。前面加debug.print E 还是不行。E的值等于0,怎么改??  Cells(E, "CS") = 0

解决方案 »

  1.   

    E等于0,是因为Z3的值为0呗。
    Z3等于0,是因为在你的“For G2 = 7 To 17”中,前面的赋值语句把Z3赋值为0。
    它报错时,点“调试”,然后看看G2的值是多少、再找对应的Z3赋值语句,它取的是哪个单元格的值;
      再到“当前活动工作表”中,看看对应的单元格是不是没有数据,或值为0。你要注意,你的Z3赋值语句:Z3 = Cells(XX, XXXX).Value
    这都没有“明确指定工作表”,那么它就是读取的“当前工作簿的当前活动工作表”,
    你在工作簿“选定的工作表”不正确,都会造成执行的错误。这样的VBA代码,写得太差劲了!