~工作簡化,不再是難事~

2016-06-07

〔VBA〕 取得Excel選取的範圍列(不需連續) / Seletion.Areas Rows

範例:依據目前工作表所選取的範圍,顯示所有列號

Private Sub PrintTSF(ByVal savePath As String)
    Dim FB As Workbook: Set FB = ActiveWorkbook     '目前活頁簿
    Dim FS As Worksheet: Set FS = ActiveSheet            '目前工作表

    Dim xArea As Range
    Dim i As Integer
    Dim iRow As Integer
    With FS
        For Each xArea In Selection.Areas
            For i = 1 To xArea.Rows.Count
                iRow = xArea.Rows(i).Row            '一筆筆取得選取的列號
                MsgBox iRow
            Next
        Next xArea
    End With
    Set FB = Nothing
    Set FS = Nothing

End Sub

0 意見:

張貼留言

Popular Posts

Copyright © 2016 Scenic's BOX. 技術提供:Blogger.