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

3、会进入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

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

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:62
阅读量:54
阅读量:94
阅读量:62
阅读量:61