請測試看看,謝謝
Sub test()
Dim Arr, Brr(1 To 7), Crr, xD, T%, i&, j&
Set xD = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1")
T = .[A1]
Arr = Range([DATA!h1], [DATA!a65536].End(3))
For i = 2 To UBound(Arr)
If Arr(i, 1) = T Then
For j = 2 To 8: n = n + 1: Brr(n) = Arr(i, j): Next
End If
Next
.[A4].Resize(7) = Application.Transpose(Brr)
.[A2] = (.Cells(1, 256).End(xlToLeft).Column - 12) / 2
Arr = .Range(.[B2], .[e65536].End(3))
ReDim Crr(1 To UBound(Arr), 1 To 5)
For i = 1 To UBound(Arr)
If Arr(i, 3) > 0 Then Arr(i, 4) = Arr(i, 3) / Arr(i, 2)
Crr(i, 1) = Arr(i, 2): Crr(i, 2) = Arr(i, 2)
Crr(i, 3) = Arr(i, 1): Crr(i, 4) = Arr(i, 3)
Crr(i, 5) = Arr(i, 4)
Next
.[B2].Resize(UBound(Arr), 4) = Arr
With Range("g2").Resize(UBound(Crr), 5)
.Value = Crr
.Sort key1:=.Item(1), Order1:=2, Header:=xlNo
Crr = .Value
End With
T = Application.Max(.Range("g2:g" & UBound(Crr)))
For i = 1 To UBound(Crr)
Crr(i, 1) = T - Crr(i, 1) + 1
Next
[H2].Resize(UBound(Crr), 1) = Crr
End With
End Sub作者: samwang 時間: 2021-8-22 08:38
[attach]33936[/attach]
[attach]33937[/attach]
不好意思,"新增需求"的程式碼~我放置的位列~不知道是哪裡有誤置?
所以在列47會產生偵錯^^"
If Arr(i, 3) > 0 Then Arr(i, 4) = Arr(i, 3) / Arr(i, 2)
尚請勞駕您賜正。謝謝您!
Private Sub CommandButton1_Click()
Dim Arr, Brr(1 To 7), Crr, xD, T%, i&, j&
Nrange = "1878" ' InputBox("請輸入DATA!的開獎期數", "輸入期數")
Tm = Timer
[L1] = ""
Application.DisplayAlerts = False
Set xD = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1")
.[A1] = Nrange
T = .[A1]
Arr = Range([DATA!h1], [DATA!a65536].End(3))
For i = 2 To UBound(Arr)
If Arr(i, 1) = T Then
For j = 2 To 8: n = n + 1: Brr(n) = Arr(i, j): Next
End If
Next
R = .Columns("M:DF").Find("*", , , , , 2).Row
Arr = .Range("M1:DF" & R)
For j = 1 To UBound(Arr, 2) Step 2
For i = 2 To UBound(Arr)
T = Arr(i, j): If T = 0 Then GoTo 98
xD(T & "/1") = xD(T & "/1") + 1
xD(T & "/2") = xD(T & "/2") + Arr(i, j + 1)
Next i
98: Next j
Arr = .Range(.[C1], .[B65536].End(3))
For i = 2 To UBound(Arr)
For j = 1 To 2: Arr(i - 1, j) = xD(Arr(i, 1) & "/" & j): Next
If xD(Arr(i, 1) & "/1") = "" Then Arr(i - 1, 1) = 0: Arr(i - 1, 2) = 0 '要新增
Next
.[C2].Resize(UBound(Arr) - 1, 2) = Arr 'C&D欄
Arr = .Range(.[B2], .[e65536].End(3))
ReDim Crr(1 To UBound(Arr), 1 To 5)
For i = 1 To UBound(Arr)
If Arr(i, 3) > 0 Then Arr(i, 4) = Arr(i, 3) / Arr(i, 2)
Crr(i, 1) = Arr(i, 2): Crr(i, 2) = Arr(i, 2)
Crr(i, 3) = Arr(i, 1): Crr(i, 4) = Arr(i, 3)
Crr(i, 5) = Arr(i, 4)
Next
.[B2].Resize(UBound(Arr), 4) = Arr
With .Range("g2").Resize(UBound(Crr), 5)
.Value = Crr
.Sort key1:=.Item(1), Order1:=2, Header:=xlNo
Crr = .Value
End With
T = Application.Max(.Range("g2:g" & UBound(Crr)))
For i = 1 To UBound(Crr)
Crr(i, 1) = T - Crr(i, 1) + 1
Next
.[H2].Resize(UBound(Crr), 1) = Crr
'版面格式.........................................................
With .Columns("A:DF")
.Font.Name = "Verdana" '字體
.HorizontalAlignment = xlCenter '左右置中
.VerticalAlignment = xlCenter '上下置中
.EntireColumn.AutoFit '自動欄寬
.EntireRow.AutoFit '自動列高
End With
End With
Sub test()
Dim Arr, Brr
With Sheets("Sheet1")
Arr = .[a1:a10]
R = .Columns("M:V").Find("*", , , , , 2).Row
Brr = .Range("M1:DF" & R)
For i = 4 To UBound(Arr)
If i < UBound(Arr) Then
.Cells(i, 1).Interior.Color = 65280
For j = 1 To UBound(Brr, 2) Step 2
For i2 = 2 To UBound(Brr)
If Brr(i2, j) = Arr(i, 1) Then
.Cells(i2, j + 12).Interior.Color = 65280
End If
Next i2
Next j
Else
.Cells(i, 1).Interior.Color = 16776960
For j = 1 To UBound(Brr, 2) Step 2
For i2 = 2 To UBound(Brr)
If Brr(i2, j) = Arr(i, 1) Then
.Cells(i2, j + 12).Interior.Color = 16776960
End If
Next i2
Next j
End If
Next
End With
End Sub作者: ziv976688 時間: 2021-8-22 22:12
是的! 謝謝您
-----------------
不好意思~
我只會最基本的 If..... Then......End If 的語法
EX :這個需求,我只會~
Sub test()
Dim i%, j%, k%
With Sheets("Sheet1")
For i = 4 To 9
For j = 2 To 50
For k = 2 To 110
If Cells(j, k).Font.ColorIndex = 7 Then
If (Cells(j, k) = Cells(i, 1)) Then
Cells(j, k).Interior.ColorIndex = 4
End If
If (Cells(j, k) = Cells(10, 1)) Then
Cells(j, k).Interior.ColorIndex = 8
End If
End If
Next k
Next j
Next i
End With
End Sub