Option Explicit
Sub Interior_ColorIndex()
Dim Arr, R&, C&, Sh, Brr, Crr, i&, x&, Y, T, Zn, N
Set Y = CreateObject("Scripting.Dictionary")
T = Timer
Set Sh = Sheets("操作表")
R = Sh.UsedRange.EntireRow.Rows.Count
C = Sh.UsedRange.EntireColumn.Columns.Count
Arr = Range(Sh.[A1], Sh.Cells(R, C))
For i = 1 To R
Zn = Arr(i, 1)
If Y.Exists(Zn) = 0 Then
N = N + 1
Y(Zn) = N
End If
Sh.Cells(i, 1).Interior.ColorIndex = Y(Zn)
If InStr("/1/3/5/9/10/11/12/13/18/21/23/25/26/29/30/31/32/41/47/49/51/52/53/54/55/56/", "/" & Y(Zn) & "/") Then
Sh.Cells(i, 1).Font.ColorIndex = 2
End If
Next
End Sub
Option Explicit
Sub Interior_Color()
Dim Arr, R&, C&, Sh, Brr, Crr, i&, x&, Y, T, Zn, N
Set Y = CreateObject("Scripting.Dictionary")
T = Timer
Set Sh = Sheets("操作表")
R = Sh.UsedRange.EntireRow.Rows.Count
C = Sh.UsedRange.EntireColumn.Columns.Count
Arr = Range(Sh.[A1], Sh.Cells(R, C))
For i = 1 To R
Zn = Arr(i, 1)
If Y.Exists(Zn) = 0 Then
N = N + 100000
Y(Zn) = N
End If
Sh.Cells(i, 1).Interior.Color = Y(Zn)
Next
End Sub作者: Andy2483 時間: 2022-11-11 11:57
本帖最後由 Andy2483 於 2022-11-11 12:04 編輯
謝謝各位前輩
找到方法:
[attach]35484[/attach]
Option Explicit
Sub Interior_Color()
Dim Arr, R&, C&, Sh, Brr, Crr, i&, X&, Y, T, Zn, N
Set Y = CreateObject("Scripting.Dictionary")
T = Timer
Set Sh = Sheets("操作表")
R = Sh.UsedRange.EntireRow.Rows.Count
C = Sh.UsedRange.EntireColumn.Columns.Count
Arr = Range(Sh.[A1], Sh.Cells(R, C))
For i = 1 To R
Zn = Arr(i, 1)
If Y.Exists(Zn) = 0 Then
N = N + 100000
Y(Zn) = N
End If
Sh.Cells(i, 1).Interior.Color = Y(Zn)
Y(Zn) = Sh.Cells(i, 1).Interior.ColorIndex
If InStr("/1/3/5/9/10/11/12/13/18/21/23/25/26/29/30/31/32/41/47/49/51/52/53/54/55/56/", "/" & Y(Zn) & "/") Then
Sh.Cells(i, 1).Font.ColorIndex = 2
End If
Next
End Sub
後學腦筋笨笨的!作者: Andy2483 時間: 2022-11-11 12:54
Option Explicit
Sub Interior_Color()
Dim Arr, R&, C&, Sh, Brr, Crr, i&, X&, Y, T, Zn, N
Set Y = CreateObject("Scripting.Dictionary")
T = Timer
Set Sh = Sheets("操作表")
R = Sh.UsedRange.EntireRow.Rows.Count
C = Sh.UsedRange.EntireColumn.Columns.Count
Arr = Range(Sh.[A1], Sh.Cells(R, C))
For i = 1 To R
Zn = Arr(i, 1)
If Y.Exists(Zn) = 0 Then
N = N + 100000
Y(Zn) = N
End If
Sh.Cells(i, 1).Interior.Color = Y(Zn)
X = Sh.Cells(i, 1).Interior.ColorIndex
If InStr("/1/3/5/9/10/11/12/13/18/21/23/25/26/29/30/31/32/41/47/49/51/52/53/54/55/56/", "/" & X & "/") Then
Sh.Cells(i, 1).Font.ColorIndex = 2
End If
Next
End Sub作者: quickfixer 時間: 2022-11-11 20:08
對比色的計算問題,google來的參數
Sub test()
With Sheets("操作表")
For i = 1 To 5000
.Cells(i, 1).Font.Color = -vbWhite * (77 * (.Cells(i, 1).Interior.Color Mod &H100) + 151 * ((.Cells(i, 1).Interior.Color \ &H100) Mod &H100) + 28 * ((.Cells(i, 1).Interior.Color \ &H10000) Mod &H100) < 32640)
Next i
End With
End Sub作者: Andy2483 時間: 2022-11-14 09:13
Sub test_quickfixer()
Dim i
With Sheets("操作表")
For i = 1 To 5000
.Cells(i, 1).Font.Color = -vbWhite * (77 * (.Cells(i, 1).Interior.Color Mod &H100) + 151 * ((.Cells(i, 1).Interior.Color \ &H100) Mod &H100) + 28 * ((.Cells(i, 1).Interior.Color \ &H10000) Mod &H100) < 32640)
'↑儲存格字色 = (-1) * 白色色彩常數16777215 * 判斷式( TURE=1 ,FALSE=0 )
'這判斷式不知道如何解讀 ??
'不過學到很多知識"
'1.&H100:是一個常數 256
'2.&H10000:是一個常數 65536
'3..Cells(i, 1).Interior.Color / &H100=390.625 ,.Cells(i, 1).Interior.Color \ &H100=390
'第一次學習到 運算式裡 \ = Int( / ) :除式的商去尾 取整數
Next i
End With
End Sub