手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

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

时间:2024-10-13 08:03:41

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

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

2、在工作表中,点击菜单栏【开发工具】,在其工具栏内,点击【visual basic】!

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

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

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

4、会弹出模块编辑窗口!

在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中,如何编写合并工作表的代码

6、在工作表的【开发工具】菜单下,点击【插入】按钮,插入一【表单】按钮,并与编写的【合敛财醣沁并工作表】代码关联,且进入命名为【合并工作表】!

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

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

在VBA中,如何编写合并工作表的代码
© 手抄报圈