テーブルに設定

 

Sub test()
    '  テーブルに設定

 

    Dim ws As Worksheet
    Set ws = ActiveSheet
    Dim tbl As ListObject


    Set tbl = ws.ListObjects.Add(xlSrcRange, ws.Range("B3").CurrentRegion, xlYes)
    tbl.Name = "テーブル1"
    tbl.TableStyle = "TableStyleMedium3"


End Sub

 

 

 

テーブルを解除

 

Sub test2()
  '   単独テーブルを解除

 

  Dim ws As Worksheet
  Set ws = ActiveSheet
  
  ws.ListObjects(1).TableStyle = ""
  ws.ListObjects(1).Unlist


End Sub

 

Sub test3()

  ’ シート内テーブル解除


  Set ws = ActiveSheet
  
  Dim ls As ListObject
    For Each ls In ws.ListObjects
        ls.Unlist
    Next ls


End Sub

 

Sub test4()

  ’ ブック内全テーブル解除

 

  Dim ws As Worksheet
  For Each ws In Worksheets

    Dim ls As ListObject
    For Each ls In ws.ListObjects
      ls.Unlist
    Next ls
  Next ws


End Sub

 

 

 

 

実行結果

 

 

― ― ― ― ― ― ― ― ― ― → Excel VBA基礎入門もくじ へ戻る 

 

参考記事