投稿日 | : 2006/05/11(Thu) 16:01 |
投稿者 | : ダンボ |
URL | : |
タイトル | : 行を結合して返す関数 |
Excel2000のVBAです。
与えられた領域の中から、条件にあった行だけを結合して返す関数を考えています。
Public Function IncludeArea(AllArea As Range) As Range
Dim Row1 As Range
Set IncludeArea = Nothing
For Each Row1 In AllArea.Rows
If 条件 Then
Set IncludeArea = Union(IncludeArea, Row1)
End If
Next Row1
End Function
で良いかなと思ったら、Unionって空オブジェクトを許さないんですね。
Public Function IncludeArea(AllArea As Range) As Range
Dim Row1 As Range
Set IncludeArea = Nothing
For Each Row1 In AllArea.Rows
If 条件 Then
If IncludeArea Is Nothing Then
Set IncludeArea = Row1
Else
Set IncludeArea = Union(IncludeArea, Row1)
End If
End If
Next Row1
End Function
で正しく動くようになったけれど、コーディングはちょっと汚い。こんな物でしょうか?
他にスマートなコードは無い?