关于DO和FOR套嵌的问题,错误1004
运行到select case cells(x1,y)时报错1004:应用程序定义或对象定义错误
是否DO里面套嵌FOR的问题?
- VB code
Sub mirco3() Dim S As Integer, X As Integer, X1 As Integer, Y As Integer, N(1 To 33) As Integer, M(1 To 33) As Integer, R As Integer X = Sheets("sheet2").UsedRange.Rows.Count For R = 1 To 33 N(R) = 0 M(R) = 0 Next R For S = 1 To 33 X1 = X - 6 Do For Y = 2 To 34 Select Case Cells(X1, Y) Case S N(S) = N(S) + 1 Select Case Cells(X1 + 1, Y) Case "●" M(S) = M(S) + 1 End Select End Select Next Y X1 = X1 - 1 Loop Until N(S) = 21 Cells(X, S + 1) = M(S) / N(S) Select Case Cells(X, S + 1) Case Is <= Cells(X - 1, S + 1) Cells(X - 4, S + 1).Interior.ColorIndex = 1 Case Else Cells(X - 4, S + 1).Interior.ColorIndex = 3 End Select Next SEnd Sub
[解决办法]
1."是否DO里面套嵌FOR的问题?"
不是,DO里面你可以嵌套任何你想要嵌套的合法循环 FOR / WHILE / DO / LOOP 等等...
2.代码结构比较混乱.
尝试定义一个string变量来保存 Cells(X1, Y).Value2,调试看看其是否有值