二维码
微世推网

扫一扫关注

当前位置: 首页 » 快闻头条 » 科技资讯 » 正文

实例23_提取多个工作表数据_实例24_根据模板生成

放大字体  缩小字体 发布日期:2023-03-13 02:12:47    作者:何昊宇    浏览次数:153
导读

实例23-提取多个工作表数据Dim wbname As StringPrivate Sub CommandButton获取_Click()'获取工作簿中包含得工作表With ThisWorkbook.Worksheets("名称列表") '清除原列表数据.Columns(1).ClearForm

实例23-提取多个工作表数据

Dim wbname As String

Private Sub CommandButton获取_Click()

'获取工作簿中包含得工作表

With ThisWorkbook.Worksheets("名称列表") '清除原列表数据

.Columns(1).ClearFormats

.Columns(1).ClearContents

End With

With ThisWorkbook.Worksheets("操作界面")

If .Cells(2, "C").Value <> "" Then

wbname = .Cells(2, "C").Value

Else

MsgBox "请输入工作簿名称(包含扩展名)"

Exit Sub

End If

End With

Dim i As Integer

For i = 1 To Workbooks(wbname).Worksheets.Count

ThisWorkbook.Worksheets("名称列表").Cells(i + 1, 1).Value = Workbooks(wbname).Worksheets(i).Name

ThisWorkbook.Worksheets("名称列表").Cells(1, 1).Value = "工作表名称"

Next i

ThisWorkbook.Worksheets("名称列表").Activate

End Sub

Private Sub CommandButton提取_Click()

With ThisWorkbook.Worksheets("操作界面")

If .Cells(2, "C").Value <> "" Then

wbname = .Cells(2, "C").Value

Else

MsgBox "请输入工作簿名称(包含扩展名)"

Exit Sub

End If

End With

Dim addrow As Long

With ThisWorkbook.Worksheets("名称列表")

Dim i As Long

Dim imax As Long

Dim j As Long

Dim jmax As Long

Dim shtname As String

imax = .Cells(1000000, 1).End(xlUp).Row

jmax = ThisWorkbook.Worksheets("提取结果").Cells(1, 10000).End(xlToLeft).Column

For i = 2 To imax

If .Cells(i, 1).Value <> "" Then

shtname = .Cells(i, 1).Value

addrow = i

With ThisWorkbook.Worksheets("提取结果")

.Rows(i).ClearContents

.Rows(i).ClearFormats

For j = 1 To jmax

If .Cells(1, j).Value <> "" Then

.Cells(i, j).Value = Workbooks(wbname).Worksheets(shtname).Range(CStr(.Cells(1, j).Value))

End If

Next j

End With

End If

Next i

MsgBox "处理完成"

End With

ThisWorkbook.Worksheets("提取结果").Activate

End Sub

实例24-根据模板生成多个工作表

Private Sub CommandButton生成_Click()

Application.ScreenUpdating = False

With ThisWorkbook.Worksheets("操作界面")

Dim wbname As String

If .Cells(2, "C").Value <> "" Then

wbname = .Cells(2, "C").Value

Else

MsgBox "请输入工作簿名称(包含扩展名)"

Exit Sub

End If

End With

With ThisWorkbook.Worksheets("名称列表")

Dim i As Long

Dim imax As Long

Dim j As Long

Dim jmax As Long

Dim shtname As String

imax = .Cells(1000000, 1).End(xlUp).Row

jmax = .Cells(1, 10000).End(xlToLeft).Column

For i = 2 To imax

If .Cells(i, 1).Value <> "" Then

shtname = .Cells(i, 1).Value

ThisWorkbook.Worksheets("模板").Copy after:=Workbooks(wbname).Worksheets(Workbooks(wbname).Worksheets.Count)

Workbooks(wbname).Worksheets(Workbooks(wbname).Worksheets.Count).Name = shtname

Workbooks(wbname).Save

For j = 2 To jmax

If .Cells(1, j).Value <> "" Then

Workbooks(wbname).Worksheets(shtname).Range(CStr(.Cells(1, j).Value)) = .Cells(i, j).Value

End If

Next j

End If

Next i

MsgBox "处理完成"

End With

Workbooks(wbname).Save

Application.ScreenUpdating = True

End Sub

 
(文/何昊宇)
打赏
免责声明
• 
本文为何昊宇原创作品•作者: 何昊宇。欢迎转载,转载请注明原文出处:http://www.udxd.com/news/show-373655.html 。本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们邮件:weilaitui@qq.com。
 

Copyright©2015-2023 粤公网安备 44030702000869号

粤ICP备16078936号

微信

关注
微信

微信二维码

WAP二维码

客服

联系
客服

联系客服:

24在线QQ: 770665880

客服电话: 020-82301567

E_mail邮箱: weilaitui@qq.com

微信公众号: weishitui

韩瑞 小英 张泽

工作时间:

周一至周五: 08:00 - 24:00

反馈

用户
反馈