运行到select case cells(x1,y)时报错1004:应用程序定义或对象定义错误
是否DO里面套嵌FOR的问题?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 S
End Sub

解决方案 »

  1.   

    1."是否DO里面套嵌FOR的问题?"
    不是,DO里面你可以嵌套任何你想要嵌套的合法循环 FOR / WHILE / DO / LOOP 等等...2.代码结构比较混乱.
    尝试定义一个string变量来保存 Cells(X1, Y).Value2,调试看看其是否有值
      

  2.   

    谢谢!我尝试了一下,发现loop until N(S)=21这句话没起作用
    是不是loop条件对于for里面的变量不起作用?
      

  3.   

    已经解决!谢谢在FOR里面加一个N(S)的判断,就能跳出循环了。
    然后控制X1的值,因为X1=X1-1减到最后变成0,CELLS无法定位才出错的。