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
5 章老師的電腦小講堂: 〔VBA〕 取得Excel選取的範圍列(不需連續) / Seletion.Areas Rows 範例:依據目前工作表所選取的範圍,顯示所有列號 Private Sub PrintTSF(ByVal savePath As String)     Dim FB As Workbook: Set FB = ActiveWorkbook     '目前活頁簿...
< >
小講堂經過多次搬移,舊文章連結及內容較難整理~
大家可以新文章為主~
每篇文章後有代碼,任何文章問題可至FB小講堂用代碼提問唷~