i-mk2! -3ページ目

i-mk2!

自分のための備忘録
OpenCVの使い方とか.

Sub testFilter()
Dim MAX_ROW As Long
Dim MAX_COL As Long
MAX_ROW = rows.Count
MAX_COL = Columns.Count

'set range of active table
Dim colBegin As Long
Dim rowBegin As Long
colBegin = 3
rowBegin = 10
Dim colEnd As Long
Dim rowEnd As Long
colEnd = Cells(rowBegin - 1, MAX_COL).End(xlToLeft).Column
rowEnd = Cells(MAX_ROW, 2).End(xlUp).row

'define FLAGs
Dim FLAG_SET As Variant
Dim FLAG_EXEC As Variant
Dim FLAG_WAIT As Variant
FLAG_SET = Cells(1, 1).Value
FLAG_EXEC = Cells(2, 1).Value
FLAG_WAIT = Cells(3, 1).Value
'define colors
Dim color_flagSet As Variant
Dim color_flagExec As Variant
Dim color_flagWait As Variant
Dim color_white As Variant
color_flagSet = RGB(0, 255, 0)
color_flagExec = RGB(255, 255, 0)
color_flagWait = RGB(127, 127, 255)
color_white = RGB(255, 255, 255)
color_gray = RGB(127, 127, 127)


'/*-----------------------------------*/
'/* main process */
'/*-----------------------------------*/
'loop for colums
Dim i As Integer
For i = colBegin To colEnd
'loop for rows
Dim currentColor As Variant
currentColor = color_white
Dim j As Integer
For j = rowBegin To rowEnd
With Cells(j, i)
'coloring cells due to VALUEs
If .Value = FLAG_SET Then
.Interior.color = color_flagSet
currentColor = color_flagExec
ElseIf .Value = FLAG_WAIT Then
.Interior.color = color_flagWait
currentColor = color_white
Else
.Interior.color = currentColor
End If

'ANY CASE: draw borders
With .Borders
.LineStyle = slContinuous
.color = color_gray
End With

End With
Next
Next



' ActiveWindow.FreezePanes = False
' ActiveWindow.FreezePanes = True
' Selection AutoFilter
' Worksheets("Sheet1").Cells(1, 1).AutoFilter Field:=1, Criteria1:="2"
' Worksheets("Sheet1").Cells(1, 1).AutoFilter Field:=1, Criteria1:="1"
' ActiveSheet.Range("$A$2,$B$20").AutoFilter Field:=1, Criteria1:="2"
End Sub