假設每二行空一行選取,二種方式,較好的方式還是設別名較佳。
' ---------------------------------------------------------------
' method1, don't use typedef range
Function MySelect1() As Range
Dim i, LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
Dim All, pre_all, cur As Range
Set pre_all = Range("B2", "F3")
For i = 5 To LastRow Step 3
Set cur = Range("B" & i, "F" & (i + 1))
Set All = Union(cur, pre_all)
Set pre_all = All
Next i
pre_all.Select
Set MySelect2 = pre_all
End Function
' ---------------------------------------------------------------
' method1, don't use typedef range
Function MySelect1() As Range
Dim i, LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
Dim All, pre_all, cur As Range
Set pre_all = Range("B2", "F3")
For i = 5 To LastRow Step 3
Set cur = Range("B" & i, "F" & (i + 1))
Set All = Union(cur, pre_all)
Set pre_all = All
Next i
pre_all.Select
Set MySelect2 = pre_all
End Function
