Private Sub CommandButton1_Click()
Dim Path As String, A, Ar(1 To 1000, 1 To 2), Ar1(), Arr, Brr(1 To 7), Crr, xD, T%, i&, j&
Dim Ar2(), Drr(1 To 16, 1 To 49), R%, K%
...
...
For i = 1 To n '開啟Ar,找檔名有"統"裝入Ar1
Set f = fs.GetFolder(Ar(i, 1))
Set fc = f.Files
For Each f1 In fc
If InStr(f1.Path, "統") Then
ReDim Preserve Ar1(n1)
Ar1(n1) = f1.Path
n1 = n1 + 1
End If
Next f1
Next i
fileOrg = ActiveWorkbook.Name
If n1 > 0 Then
R = 33
表頭 = Array("總次數", "最大", "次大", "三大", "", "最小", "次小", "三小", _
"倍數", "最大", "次大", "三大", "", "最小", "次小", "三小")
For i1 = 0 To n - 1 '開啟Ar1
Set WB = Workbooks.Open(Ar1(i1))
fn = Split(Ar1(i1), "_")(5)
With Sheets(1)
If .FilterMode Then .ShowAllData
With .Range(.[B1], .[E65536].End(3))
Crr = .Value
.Sort Key1:=.Item(3), Order1:=2, Header:=1
Arr = .Value
.Value = Crr
End With
End With
WB.Close
For i = 2 To 4 '前3數值
ReDim Preserve Ar2(K): Ar2(K) = Arr(i, 1): K = K + 1
Next
For i = UBound(Arr) To 48 Step -1 '最後3數值
ReDim Preserve Ar2(K): Ar2(K) = Arr(i, 1): K = K + 1
Next
For i = 0 To UBound(Ar2)
T = Ar2(i)
If i < 3 Then
Drr(i + 1, T) = "V": Drr(i + 9, T) = "V"
Else
Drr(i + 2, T) = "V": Drr(i + 10, T) = "V"
End If
Next
With Sheets("Sheet1")
.Range("a" & R) = fn
.Range("b" & R).Resize(16) = Application.Transpose(表頭)
.Range("c" & R + 1).Resize(15, 49) = Drr
R = .[b65536].End(3).Row + 1
End With
Erase Ar2: Erase Drr: K = 0
Next
End If
Set fs = Nothing: Set f = Nothing: Set fc = Nothing
...
...作者: ziv976688 時間: 2021-9-6 14:14
Private Sub CommandButton1_Click()
Dim Path As String, A, Ar(1 To 1000, 1 To 2), Ar1(), Arr, Brr(1 To 7), Crr, xD, T%, i&, j&
Dim Ar2(), Drr(1 To 16, 1 To 49), Arr1,R%, K%, CR%, R1%
...
...
fileOrg = ActiveWorkbook.Name
If n1 > 0 Then
R = 33
表頭 = Array("總次數", "最大", "次大", "三大", "", "最小", "次小", "三小", _
"倍數", "最大", "次大", "三大", "", "最小", "次小", "三小")
For i1 = 0 To n - 1 '開啟Ar1
Set WB = Workbooks.Open(Ar1(i1))
fn = Split(Ar1(i1), "_")(5)
With Sheets(1)
If .FilterMode Then .ShowAllData
With .Range(.[B1], .[E65536].End(3))
Crr = .Value
.Sort Key1:=.Item(3), Order1:=2, Header:=1
Arr = .Value '總次數
.Sort Key1:=.Item(4), Order1:=1, Header:=1
Arr1 = .Value '倍數
.Value = Crr
End With
End With
WB.Close
For i = 2 To 4 '總次數:最大3數值
ReDim Preserve Ar2(K): Ar2(K) = Arr(i, 1): K = K + 1
Next
For i = UBound(Arr) To 48 Step -1 '總次數:最小3數值
ReDim Preserve Ar2(K): Ar2(K) = Arr(i, 1): K = K + 1
Next
For i = UBound(Arr1) To 48 Step -1 '倍數:最大3數值
ReDim Preserve Ar2(K): Ar2(K) = Arr1(i, 1): K = K + 1
Next
For i = 2 To 4 '倍數:最小3數值
ReDim Preserve Ar2(K): Ar2(K) = Arr1(i, 1): K = K + 1
Next
For i = 0 To UBound(Ar2)
T = Ar2(i)
If CR = 3 Then CR = 0: R1 = R1 + 2 Else R1 = R1 + 1
Drr(R1, T) = "V": CR = CR + 1
Next
With Sheets("Sheet1")
.Range("a" & R) = fn
.Range("b" & R).Resize(16) = Application.Transpose(表頭)
.Range("c" & R + 1).Resize(15, 49) = Drr
R = .[b65536].End(3).Row + 2
End With
Erase Ar2: Erase Drr: K = 0: CR = 0: R1 = 0
Next
End If
Set fs = Nothing: Set f = Nothing: Set fc = Nothing
...
...作者: ziv976688 時間: 2021-9-6 22:36
Private Sub CommandButton1_Click()
Dim Path As String, A, Ar(1 To 1000, 1 To 2), Ar1(), Arr, Brr(1 To 7), Crr, xD, T%, i&, j&
Dim Drr(1 To 3, 1 To 49), Arr1, R%, K21%, K22%, K31%, K32%, R21%, R22%, R31%, R32%, T1%
Dim Ar21(1 To 10, 1 To 2), Ar22(1 To 10, 1 To 2), Ar31(1 To 10, 1 To 2), Ar32(1 To 10, 1 To 2)
Set xD = CreateObject("Scripting.Dictionary")
...
...
If n1 > 0 Then
R = 33
表頭 = Array("總次數", "最大", "次大", "三大", "", "最小", "次小", "三小", _
"倍數", "最大", "次大", "三大", "", "最小", "次小", "三小")
For i1 = 0 To n - 1 '開啟Ar1
Set WB = Workbooks.Open(Ar1(i1))
fn = Split(Ar1(i1), "_")(5)
With Sheets(1)
If .FilterMode Then .ShowAllData
With .Range(.[B1], .[E65536].End(3))
Crr = .Value
.Sort Key1:=.Item(3), Order1:=2, Header:=1
Arr = .Value '總次數
.Sort Key1:=.Item(4), Order1:=2, Header:=1
Arr1 = .Value '倍數
.Value = Crr
End With
End With
WB.Close
For i = 2 To UBound(Arr) '總次數:最大3數值
K21 = K21 + 1: If K21 > 3 And xD(Arr(i, 3) & "_21") <> 1 Then Exit For
Ar21(K21, 1) = Arr(i, 1): Ar21(K21, 2) = Arr(i, 3): xD(Arr(i, 3) & "_21") = 1
Next
For i = UBound(Arr) To 2 Step -1 '總次數:最小3數值
K22 = K22 + 1: If K22 > 3 And xD(Arr(i, 3) & "_22") <> 1 Then Exit For
Ar22(K22, 1) = Arr(i, 1): Ar22(K22, 2) = Arr(i, 3): xD(Arr(i, 3) & "_22") = 1
Next
For i = 2 To UBound(Arr1) '倍數:最大3數值
K31 = K31 + 1: If K31 > 3 And xD(Arr1(i, 4) & "_31") <> 1 Then Exit For
Ar31(K31, 1) = Arr1(i, 1): Ar31(K31, 2) = Arr1(i, 4): xD(Arr1(i, 4) & "_31") = 1
Next
For i = UBound(Arr1) To 2 Step -1 '倍數:最小3數值
K32 = K32 + 1: If K32 > 3 And xD(Arr1(i, 4) & "_32") <> 1 Then Exit For
Ar32(K32, 1) = Arr1(i, 1): Ar32(K32, 2) = Arr1(i, 4): xD(Arr1(i, 4) & "_32") = 1
Next
With Sheets("Sheet1")
.Range("a" & R) = fn
.Range("b" & R).Resize(16) = Application.Transpose(表頭)
For i = 1 To K21 - 1 '總次數:最大3數值
T = Ar21(i, 2): If T1 = T Then R21 = R21 Else R21 = R21 + 1
Drr(R21, Ar21(i, 1)) = "V": T1 = T
Next
.Range("c" & R + 1).Resize(3, 49) = Drr
R = .[b65536].End(3).Row - 10: Erase Drr: T1 = 0
For i = 1 To K22 - 1 '總次數:最小3數值
T = Ar22(i, 2): If T1 = T Then R22 = R22 Else R22 = R22 + 1
Drr(R22, Ar22(i, 1)) = "V": T1 = T
Next
.Range("c" & R).Resize(3, 49) = Drr
R = .[b65536].End(3).Row - 6: Erase Drr: T1 = 0
For i = 1 To K31 - 1 '倍數:最大3數值
T = Ar31(i, 2): If T1 = T Then R31 = R31 Else R31 = R31 + 1
Drr(R31, Ar31(i, 1)) = "V": T1 = T: T1 = 0
Next
.Range("c" & R).Resize(3, 49) = Drr
R = .[b65536].End(3).Row - 2: Erase Drr: T1 = 0
For i = 1 To K32 - 1 '倍數:最小3數值
T = Ar32(i, 2): If T1 = T Then R32 = R32 Else R32 = R32 + 1
Drr(R32, Ar32(i, 1)) = "V": T1 = T: T1 = 0
Next
.Range("c" & R).Resize(3, 49) = Drr
R = .[b65536].End(3).Row + 2: Erase Drr: T1 = 0
End With
Erase Ar21: Erase Ar22: Erase Ar31: Erase Ar32: xD.RemoveAll
K21 = 0: K22 = 0: K31 = 0: K32 = 0: R21 = 0: R22 = 0: R31 = 0: R32 = 0
Next
End If
Set fs = Nothing: Set f = Nothing: Set fc = Nothing
...
...作者: samwang 時間: 2021-9-7 13:51
Private Sub CommandButton1_Click()
Dim xD, Ar21(1 To 10, 1 To 2), Ar22(1 To 10, 1 To 2), Ar31(1 To 10, 1 To 2), Ar32(1 To 10, 1 To 2)
Dim Path As String, A, Ar(1 To 1000, 1 To 2), Ar1(), Arr, Brr(1 To 7), Crr, T, i&, j&
Dim Drr(1 To 3, 1 To 49), Arr1, R%, K21%, K22%, K31%, K32%, R21%, R22%, R31%, R32%, T1
Set xD = CreateObject("Scripting.Dictionary")
Set fs = CreateObject("Scripting.FileSystemObject")
A = ThisWorkbook.Path '每個資料夾名稱裝入Ar
Set f = fs.GetFolder(A)
Set fc = f.SubFolders
For Each f1 In fc
n = n + 1
Ar(n, 1) = f1.Path
Ar(n, 2) = Split(Split(f1.Name, "_")(4), "-")(0)
Next
For i = 1 To UBound(Ar) 'Ar由大至小排序
For j = i + 1 To UBound(Ar)
If Ar(i, 2) < Ar(j, 2) Then
A = Ar(i, 1)
Ar(i, 1) = Ar(j, 1)
Ar(j, 1) = A
End If
Next j
Next i
For i = 1 To n '開啟Ar,找檔名有"統"裝入Ar1
Set f = fs.GetFolder(Ar(i, 1))
Set fc = f.Files
For Each f1 In fc
If InStr(f1.Path, "統") Then
ReDim Preserve Ar1(n1)
Ar1(n1) = f1.Path
n1 = n1 + 1
End If
Next f1
Next i
fileOrg = ActiveWorkbook.Name
If n1 > 0 Then
R = 33
表頭 = Array("總次數", "最大", "次大", "三大", "", "最小", "次小", "三小", _
"倍數", "最大", "次大", "三大", "", "最小", "次小", "三小")
For i1 = 0 To n - 1 '開啟Ar1
Set WB = Workbooks.Open(Ar1(i1))
fn = Split(Ar1(i1), "_")(5)
With Sheets(1)
If .FilterMode Then .ShowAllData
With .Range(.[B1], .[E65536].End(3))
Crr = .Value
.Sort Key1:=.Item(3), Order1:=2, Header:=1
Arr = .Value '總次數
.Sort Key1:=.Item(4), Order1:=2, Header:=1
Arr1 = .Value '倍數
.Value = Crr
End With
End With
WB.Close
For i = 2 To UBound(Arr) '總次數:最大3數值
K21 = K21 + 1: If xD.Count > 2 And Not xD.Exists(Arr(i, 3) & "") Then Exit For
Ar21(K21, 1) = Arr(i, 1): Ar21(K21, 2) = Arr(i, 3): xD(Arr(i, 3) & "") = 1
Next
xD.RemoveAll
For i = UBound(Arr) To 2 Step -1 '總次數:最小3數值
K22 = K22 + 1: If xD.Count > 2 And Not xD.Exists(Arr(i, 3) & "") Then Exit For
Ar22(K22, 1) = Arr(i, 1): Ar22(K22, 2) = Arr(i, 3): xD(Arr(i, 3) & "") = 1
Next
xD.RemoveAll
For i = 2 To UBound(Arr1) '倍數:最大3數值
K31 = K31 + 1: If xD.Count > 2 And Not xD.Exists(Arr1(i, 4) & "") Then Exit For
Ar31(K31, 1) = Arr1(i, 1): Ar31(K31, 2) = Arr1(i, 4): xD(Arr1(i, 4) & "") = 1
Next
xD.RemoveAll
For i = UBound(Arr1) To 2 Step -1 '倍數:最小3數值
K32 = K32 + 1: If xD.Count > 2 And Not xD.Exists(Arr1(i, 4) & "") Then Exit For
Ar32(K32, 1) = Arr1(i, 1): Ar32(K32, 2) = Arr1(i, 4): xD(Arr1(i, 4) & "") = 1
Next
xD.RemoveAll
With Sheets("Sheet1")
.Range("a" & R) = fn
.Range("b" & R).Resize(16) = Application.Transpose(表頭)
For i = 1 To K21 - 1 '總次數:最大3數值
T = Ar21(i, 2): If T1 = T Then R21 = R21 Else R21 = R21 + 1
Drr(R21, Ar21(i, 1)) = "V": T1 = T
Next
.Range("c" & R + 1).Resize(3, 49) = Drr
R = .[b65536].End(3).Row - 10: Erase Drr: T1 = 0
For i = 1 To K22 - 1 '總次數:最小3數值
T = Ar22(i, 2): If T1 = T Then R22 = R22 Else R22 = R22 + 1
Drr(R22, Ar22(i, 1)) = "V": T1 = T
Next
.Range("c" & R).Resize(3, 49) = Drr
R = .[b65536].End(3).Row - 6: Erase Drr: T1 = 0
For i = 1 To K31 - 1 '倍數:最大3數值
T = Ar31(i, 2): If T1 = T Then R31 = R31 Else R31 = R31 + 1
Drr(R31, Ar31(i, 1)) = "V": T1 = T
Next
.Range("c" & R).Resize(3, 49) = Drr
R = .[b65536].End(3).Row - 2: Erase Drr: T1 = 0
For i = 1 To K32 - 1 '倍數:最小3數值
T = Ar32(i, 2): If T1 = T Then R32 = R32 Else R32 = R32 + 1
Drr(R32, Ar32(i, 1)) = "V": T1 = T 'If R32 < 4 Then:
Next
.Range("c" & R).Resize(3, 49) = Drr
R = .[b65536].End(3).Row + 2: Erase Drr: T1 = 0
End With
Erase Ar21: Erase Ar22: Erase Ar31: Erase Ar32: xD.RemoveAll
K21 = 0: K22 = 0: K31 = 0: K32 = 0: R21 = 0: R22 = 0: R31 = 0: R32 = 0
Next
End If
Set fs = Nothing: Set f = Nothing: Set fc = Nothing '...................................................................
Set xD = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1")
.[A1] = Nrange
.[A2].Formula = "=Count(A33:A2000) & ""期""": .[A2] = .[A2].Value 'A欄的期個數
.[A3] = "開獎號碼"
.[A4:A10].Formula = "=IF(A$1="""","""",VLOOKUP(A$1,DATA!$A:$H,ROW()-2,))": .[A4:A10] = .[A4:A10].Value '=Nrange期數的開獎號碼
.[A32] = "期數"