Excel Macro - Select all cells with data and format as table

后端 未结 1 1204
逝去的感伤
逝去的感伤 2020-12-10 01:43

Is it possible to write a macro that can format a table out of any active selection? For instance, I have a macro that will basically just do a Ctrl+Shift+End range selectio

相关标签:
1条回答
  • 2020-12-10 02:21

    Try this one for current selection:

    Sub A_SelectAllMakeTable2()
        Dim tbl As ListObject
        Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
        tbl.TableStyle = "TableStyleMedium15"
    End Sub
    

    or equivalent of your macro (for Ctrl+Shift+End range selection):

    Sub A_SelectAllMakeTable()
        Dim tbl As ListObject
        Dim rng As Range
    
        Set rng = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
        Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes)
        tbl.TableStyle = "TableStyleMedium15"
    End Sub
    
    0 讨论(0)
提交回复
热议问题