Excel 比對資料,使用Find 或FindNext效率要高好幾倍
Function 將取樣值上色()
LotoShowCon=100048
'初始值
Dim ShowBall As Integer
All_Ball = 49 '總球數
ShowBall = 7
'變數設定
Dim ShtLotoOrg As Object, Sht348 As Object
Set ShtLotoOrg = Sheets("大樂透落球")
Set Sht348 = Sheets(LotoShowCon & "取位")
'主程式
Dim Sht348_Ball As Object, Org_Ball As String
Dim arrBallchk
ReDim arrBallchk(1 To ShowBall) As Variant
With ShtLotoOrg
lLastRow = .Range("B" & Cells.Rows.Count).End(xlUp).Row
Set Fld = .Range(.Cells(3, 2), .Cells(lLastRow, 2))
Set Loto_Rng = Fld.Find(What:=LotoShowCon, LookAt:=xlWhole)
For i = 1 To ShowBall
arrBallchk(i) = Loto_Rng.Offset(-1, i).Value
Next
End With
Set sht348_Rng = Sht348.Range("C" & Cells.Rows.Count).End(xlUp).CurrentRegion
For i = 1 To UBound(arrBallchk, 1)
Set chkBall = sht348_Rng.Find(What:=arrBallchk(i), LookAt:=xlWhole)
chkBall.Activate
sht348_Cells = Application.CountIf(sht348_Rng, chkBall)
For j = 1 To sht348_Cells
sht348_Rng.FindNext(After:=ActiveCell).Activate
ActiveCell.Interior.ColorIndex = 3
Next j
Next i
End Function
LotoShowCon=100048
'初始值
Dim ShowBall As Integer
All_Ball = 49 '總球數
ShowBall = 7
'變數設定
Dim ShtLotoOrg As Object, Sht348 As Object
Set ShtLotoOrg = Sheets("大樂透落球")
Set Sht348 = Sheets(LotoShowCon & "取位")
'主程式
Dim Sht348_Ball As Object, Org_Ball As String
Dim arrBallchk
ReDim arrBallchk(1 To ShowBall) As Variant
With ShtLotoOrg
lLastRow = .Range("B" & Cells.Rows.Count).End(xlUp).Row
Set Fld = .Range(.Cells(3, 2), .Cells(lLastRow, 2))
Set Loto_Rng = Fld.Find(What:=LotoShowCon, LookAt:=xlWhole)
For i = 1 To ShowBall
arrBallchk(i) = Loto_Rng.Offset(-1, i).Value
Next
End With
Set sht348_Rng = Sht348.Range("C" & Cells.Rows.Count).End(xlUp).CurrentRegion
For i = 1 To UBound(arrBallchk, 1)
Set chkBall = sht348_Rng.Find(What:=arrBallchk(i), LookAt:=xlWhole)
chkBall.Activate
sht348_Cells = Application.CountIf(sht348_Rng, chkBall)
For j = 1 To sht348_Cells
sht348_Rng.FindNext(After:=ActiveCell).Activate
ActiveCell.Interior.ColorIndex = 3
Next j
Next i
End Function
留言
張貼留言