VB6.0用掲示板の過去のログ(No.2)−VBレスキュー(花ちゃん)
[記事リスト] [新規投稿] [新着記事] [ワード検索] [管理用]

投稿日: 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

で正しく動くようになったけれど、コーディングはちょっと汚い。こんな物でしょうか?
他にスマートなコードは無い?


- 返信フォーム (この記事に返信する場合は下記フォームから投稿して下さい)

- VBレスキュー(花ちゃん) - - Web Forum -