在VBA中,如何编写合并工作表的代码

2024-10-13 08:03:41

1、实例【通过运行VBA代码将1至3月份工作表中的内容复制到“年度”工作表中?】

在VBA中,如何编写合并工作表的代码

3、会进入VBA编辑界面!点击菜单栏【插入】,在其下拉菜单中,选择【模块】!

在VBA中,如何编写合并工作表的代码

5、在代码编辑窗口输入以下代码:Sub 合并工作表()Dim i As Integer巳呀屋饔, j%, k%, mth As Worksheet, yer As WorksheetSet yer 租涫疼迟= Sheets("年度")For i = 1 To 3 Set mth = Sheets(i & "月份") j = mth.UsedRange.Rows.Count m = mth.Cells(2, mth.Columns.Count).End(xlToLeft).Column k = yer.Cells(2, 1).CurrentRegion.Rows.Count mth.Range(mth.[a3], mth.Cells(j, m)).Copy yer.Paste Cells(k + 1, 2) yer.Cells(k + 1, 1).Resize(j - 2) = i & "月"NextEnd Sub

在VBA中,如何编写合并工作表的代码

7、点击【合并工作表】按钮!1至3月份工作表中的内容瞬间被复制到“年度”工作表中!

在VBA中,如何编写合并工作表的代码
猜你喜欢