|
数据是总表,根据班级用代发拆分后,我再在数据表中,添加了数据(如图标黄色数据),然后无法自动更新,该怎么办? 网上说复制以下代码就能实现,也不知道是我哪里操作错误,总是不成功,请大神详细的写一下操作步骤。
自动更新代码如下:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveWorkbook.RefreshAll
End Sub
使用的拆分代码如下:
Sub 按列拆分()
Dim rng As Range, i As Integer, sht As Worksheet, sh As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Rem 要根据哪一列进行拆分
Set sht = Worksheets("数据")
Set rng = Application.InputBox(prompt:="选择拆分列", Type:=8)
rng.EntireColumn.Copy sht.[h1]
sht.Range("H:H").RemoveDuplicates Columns:=1, Header:=xlYes
Rem 添加工作表,总表里筛选符合条件表格复制粘贴至目标表
For i = 2 To sht.[h65536].End(xlUp).Row
Worksheets.Add.Name = sht.Cells(i, "h").Value
sht.Select
[a1].CurrentRegion.Select
Selection.AutoFilter Field:=rng.Column, Criteria1:=sht.Cells(i, "h").Value
Selection.Copy Worksheets(sht.Cells(i, "h").Value).[a1]
Worksheets(sht.Cells(i, "h").Value).Select
Columns("A:E").Select
Selection.Columns.AutoFit
[a1].Select
Next
Rem 总表清除筛选,删除辅助的h列
sht.Select
Selection.AutoFilter
[h:h].Clear
[a1].Select
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|
|