我有一張7800行約2382列約一張。 (19.5Million Cells)如何加快我的VBA腳本
在此之外,我有22 x列,我實際上感興趣,其中有5 x位數字散佈在其中。
本質上,如果第一列中的數字然後在其他21 x列中的任何一列中找到,我想打開相關的行,列中的單元格內部爲紅色。
我有這個工作,我相信與附加的代碼,但它需要大約3 x小時運行。
我想問一下,這是一個合理的時間(3 x小時)與電子表格的大小?
如果你期望例程更快,我將非常感謝你的指導,應該如何編寫腳本。
Sub FindMatch()
Dim rng_1 As Range
Dim rng_2 As Range
Dim rng_3 As Range
Dim rng_4 As Range
Dim rng_5 As Range
Dim rng_6 As Range
Dim rng_7 As Range
Dim rng_8 As Range
Dim rng_9 As Range
Dim rng_10 As Range
Dim rng_11 As Range
Dim rng_12 As Range
Dim rng_13 As Range
Dim rng_14 As Range
Dim rng_15 As Range
Dim rng_16 As Range
Dim rng_17 As Range
Dim rng_18 As Range
Dim rng_19 As Range
Dim rng_20 As Range
Dim rng_21 As Range
Dim rng_22 As Range
Dim rngRef_1 As Range
Dim rngRef_2 As Range
Dim rngRef_3 As Range
Dim rngRef_4 As Range
Dim rngRef_5 As Range
Dim rngRef_6 As Range
Dim rngRef_7 As Range
Dim rngRef_8 As Range
Dim rngRef_9 As Range
Dim rngRef_10 As Range
Dim rngRef_11 As Range
Dim rngRef_12 As Range
Dim rngRef_13 As Range
Dim rngRef_14 As Range
Dim rngRef_15 As Range
Dim rngRef_16 As Range
Dim rngRef_17 As Range
Dim rngRef_18 As Range
Dim rngRef_19 As Range
Dim rngRef_20 As Range
Dim rngRef_21 As Range
Dim rngRef_22 As Range
Application.Calculation = xlManual
Application.ScreenUpdating = False
Set rng_1 = Worksheets("Sheet1").Range("$DQ$2:$DQ$8000")
Set rng_2 = Worksheets("Sheet1").Range("$GW$2:$GW$8000")
Set rng_3 = Worksheets("Sheet1").Range("$KC$2:$KC$8000")
Set rng_4 = Worksheets("Sheet1").Range("$NI$2:$NI$8000")
Set rng_5 = Worksheets("Sheet1").Range("$QO$2:$QO$8000")
Set rng_6 = Worksheets("Sheet1").Range("$TU$2:$TU$8000")
Set rng_7 = Worksheets("Sheet1").Range("$XA$2:$XA$8000")
Set rng_8 = Worksheets("Sheet1").Range("$AAG$2:$AAG$8000")
Set rng_9 = Worksheets("Sheet1").Range("$ADM$2:$ADM$8000")
Set rng_10 = Worksheets("Sheet1").Range("$AGS$2:$AGS$8000")
Set rng_11 = Worksheets("Sheet1").Range("$AJY$2:$AJY$8000")
Set rng_12 = Worksheets("Sheet1").Range("$ANE$2:$ANE$8000")
Set rng_13 = Worksheets("Sheet1").Range("$AQK$2:$AQK$8000")
Set rng_14 = Worksheets("Sheet1").Range("$ATQ$2:$ATQ$8000")
Set rng_15 = Worksheets("Sheet1").Range("$AWW$2:$AWW$8000")
Set rng_16 = Worksheets("Sheet1").Range("$BAC$2:$BAC$8000")
Set rng_17 = Worksheets("Sheet1").Range("$BDI$2:$BDI$8000")
Set rng_18 = Worksheets("Sheet1").Range("$BGO$2:$BGO$8000")
Set rng_19 = Worksheets("Sheet1").Range("$BJU$2:$BJU$8000")
Set rng_20 = Worksheets("Sheet1").Range("$BNA$2:$BNA$8000")
Set rng_21 = Worksheets("Sheet1").Range("$BQG$2:$BQG$8000")
Set rng_22 = Worksheets("Sheet1").Range("$BTM$2:$BTM$8000")
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_2 In rng_2
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_2.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_3 In rng_3
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_3.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_4 In rng_4
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_4.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_5 In rng_5
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_5.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_6 In rng_6
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_6.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_7 In rng_7
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_7.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_8 In rng_8
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_8.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_9 In rng_9
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_9.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_10 In rng_10
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_10.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_11 In rng_11
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_11.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_12 In rng_12
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_12.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_13 In rng_13
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_13.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_14 In rng_14
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_14.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_15 In rng_15
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_15.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_16 In rng_16
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_16.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_17 In rng_17
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_17.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_18 In rng_18
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_18.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_19 In rng_19
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_19.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_20 In rng_20
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_20.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_21 In rng_21
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_21.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
For Each rngRef_1 In rng_1
For Each rngRef_22 In rng_22
If rngRef_1.Value <> "" Then
If rngRef_1.Value = rngRef_22.Value Then
rngRef_1.Offset(0, -120).Interior.Color = RGB(255, 0, 0)
End If
End If
Next
Next
Rem -----------------------------------------------------
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
你> 19M細胞和<100K號。爲什麼不先找到所有5位數的數字,然後只是將A列中的那些數字變成紅色,然後找到? –
嗨亞歷克斯,你會怎麼做,我看不到一種方法 – user3274198