Sub HowToUse()
ReduceRangeR(Selection).Select
End Sub
Private Function ReduceRangeR(a1 As Range) As Range
r1 = a1.Row
c1 = a1.Column
r2 = a1.Rows.Count + r1 - 1
c2 = a1.Columns.Count + c1 - 1
NewRow = r1
For c = c1 To c2
If Len(Cells(r2, c)) > 0 Then
NewRow = r2
GoTo xxx
End If
r = Cells(r2, c).End(xlUp).Row
If r > NewRow Then
NewRow = r
End If
Next c
xxx:
Set ReduceRangeR = Range(Cells(r1, c1), Cells(NewRow, c2))
End Function
引数にRangeをとって、下方の空白行を除いたRangeを返します。実行前
実行後
0 件のコメント:
コメントを投稿