Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Private Sub Workbook_AddinInstall()
- '
- ' Application.MacroOptions _
- ' Macro:="NONBLANK", _
- ' Description:="空白でないセルを検索します。", _
- ' Category:=5, _
- ' ArgumentDescriptions:=("には、連続したセル範囲を指定します。|には TRUE または FALSE のいずれかを指定し、値を検索する方向を指定します。|には、取得対象に含めない値を指定します。", "|")
- '
- 'End Sub
- Option Explicit
- Function NONBLANK(検査範囲 As Range, Optional 先頭から検索 As Boolean = False, Optional 除外する値 As String = "") As Range
- Dim cellIndex As Long
- Dim candidateCell As Range
- If 先頭から検索 Then
- ' 先頭(左上)から検索
- Set NONBLANK = 検査範囲(1)
- For cellIndex = 1 To 検査範囲.Count
- Set candidateCell = 検査範囲(cellIndex)
- If Not IsEmpty(candidateCell) Then
- If Not candidateCell Like 除外する値 Then
- Set NONBLANK = candidateCell
- Exit For
- End If
- End If
- Next cellIndex
- Else
- ' 末尾(右下)から検索
- Set NONBLANK = 検査範囲(検査範囲.Count)
- For cellIndex = 検査範囲.Count To 1 Step -1
- Set candidateCell = 検査範囲(cellIndex)
- If Not IsEmpty(candidateCell) Then
- If Not candidateCell Like 除外する値 Then
- Set NONBLANK = candidateCell
- Exit For
- End If
- End If
- Next cellIndex
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement