这是因为这不是写这段代码的有效方法,或者它只是在像这样的excel上工作很慢?我在Windows 8 64位上使用Excel 2007。我的办公室笔记本是一个非常新的,最新的I5 CPU。下面是代码:为什么我的循环太慢?
Private Sub CommandButton1_Click()
Sheets("data").Select
For rcounter = 2 To 45752
For xcounter = 26 To 50
For ycounter = 2 To 414
If (Cells(1, xcounter) = Cells(rcounter, 4)) Then
If (CInt(Cells(ycounter, 25)) = CInt(Cells(rcounter, 10))) Then
Cells(ycounter, xcounter).Value = Cells(ycounter, xcounter).Value + 1
End If
End If
Next ycounter
Next xcounter
Next rcounter
End Sub
基本上在同一张表中,列A和列B有45,751条记录(对于rcounter = 2到45752)。列A具有这些可能的值(对于xcounter = 26到50)并且列B具有这些可能的值(对于ycounter = 2到414),则这个x轴xcounter和y asix ycounter表,用这一行一行一行地搜索I每当它出现时都需要加1。 – Teemo