0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excel VBA

Last updated at Posted at 2025-03-12

1.将单元格移动到1,1单元格,

Application.GoTo Cells(1, 1), False
  • False为不移动画面,只移动格子,不伴随滚动条的移动,也可以设置成True

用例:

Sub SellToA1()
    Dim ws As Worksheet
    Dim memo As String
    memo = ""
    For Each ws In ThisWorkbook.Worksheets
        If memo = "" Then memo = ws.Name
        ws.Activate
        Application.GoTo Cells(1, 1), True
    Next ws
    ThisWorkbook.Worksheets(memo).Activate
End Sub

2.设置范围并命名

ActiveWorkbook.Names.Add Name:="PIB_DATA", RefersToR1C1:=ActiveSheet.Range(Cells(1, 1), Cells(w_row, W_COL))

3.清除Pivot里面的项目数据

For Each pvtfield In Worksheets("Sheet名").PivotTables("ピボットテーブル2").PivotFields
    For Each pvtitem In pvtfield.PivotItems
        pvtitem.Delete
    Next
  Next

4.更新指定的Pivot

ActiveSheet.PivotTables("ピボットテーブル1").RefreshTable
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?