|
'最初のFor Each は Unionメソッド を使う為に初期Rangeをセット
'次ののFor Each で Unionメソッド
Sub test()
Dim FC_Ch_R As Range
Dim FC2 As Range
Dim FC3 As Range
Dim FC As Range
Const C_no2 As Long = 2
Const C_no3 As Long = 3
For Each FC_Ch_R In Selection
With FC_Ch_R.Font
' Debug.Print .ColorIndex
Select Case .ColorIndex
Case C_no2
Set FC2 = FC_Ch_R
Case C_no3
Set FC3 = FC_Ch_R
Case Is <> C_no2, Is <> C_no3
Set FC = FC_Ch_R
End Select
End With
Next
For Each FC_Ch_R In Selection
With FC_Ch_R.Font
Select Case .ColorIndex
Case C_no2
Set FC2 = Union(FC_Ch_R, FC2)
Case C_no3
Set FC3 = Union(FC_Ch_R, FC3)
Case Is <> C_no2, Is <> C_no3
Set FC = Union(FC_Ch_R, FC)
End Select
End With
Next
Debug.Print FC2.Address(0, 0)
Debug.Print FC3.Address(0, 0)
Debug.Print FC.Address(0, 0)
End Sub
前半のループがムダだと思うんですけど・・・。
ほかに良い方法があるんでしょうか?
|
|