excel,自动将子工作表内的内容汇总到总表中,用VBA怎么写? 30
可以这么实现,在对应子工作表输入内容时,当最新一行输入完成后,自动更新数据到总览表中。代码放到两个子工作表里面即可。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 And Target.Column = 4 Then
Sheets("总览").Range("A65536").End(xlUp).Offset(1, 0).Value = ActiveSheet.Name
Target.Offset(, -3).Resize(1, 4).Copy Sheets("总览").Range("B65536").End(xlUp).Offset(1, 0)
Application.StatusBar = ChrW(12304) & ChrW(20316) & ChrW(32773) & Chr(81) & Chr(81) & Chr(49) & Chr(51) & Chr(50) & Chr(55) & Chr(49) & Chr(56) & Chr(51) & Chr(54) & Chr(56) & Chr(56) & ChrW(12305)
End If
End Sub
Range("a2:D65536") = ""
Dim n
For n = 2 To Sheets.Count
Cells(Range("a65536").End(xlUp).Row + 1, "a") = Sheets(n).Name
x = Sheets(n).Range("B655536").End(xlUp).Row
Sheets(n).Select
Sheets(n).Range(Sheets(n).Cells(x, "B"), Sheets(n).Cells(x, "D")).Copy Cells(Range("b65536").End(xlUp).Row + 1, "b")
Next
Sheets("总览").Select
End Sub
放在 总览 表的vba窗口