Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1144|回复: 3

[已解决]档案转换

[复制链接]
发表于 2022-9-5 14:23 | 显示全部楼层 |阅读模式
本帖最后由 lkk0063 于 2022-9-7 14:48 编辑

需求:
按下 Add to Out 按钮,自动将"In"内容输入到"Out"中
0.jpg
最佳答案
2022-9-5 18:21
数据不多,用复制黏贴就可以啦。
Private Sub CommandButton2_Click()
    Set WK = Workbooks.Open(ThisWorkbook.Path & "\Out.Xlsm")
    With WK.Sheets("BB")
        W = .[A65536].End(3).Row
        If W < 6 Then W = 6
        .Cells(W, 1) = Split([G1], "-")(0)
        .Cells(W, 2) = Year([C1])
        .Cells(W, 3) = [C1]
        .Cells(W, 4) = [E1]
        For i = 3 To 17
            Set C = .Cells.Find(Cells(i, "A").Value, lookat:=xlWhole)
            CL = C.Column
            Range(Cells(i, "F"), Cells(i, "J")).Copy .Cells(W, CL)
        Next
    End With
    WK.Close True
End Sub

test.zip

130.23 KB, 下载次数: 4

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2022-9-5 15:52 | 显示全部楼层
你确定“OUT”文件中“1、2、3、....”是这样的吗?“4、5”又放在哪列?
无标题.jpg
回复

使用道具 举报

 楼主| 发表于 2022-9-5 16:18 | 显示全部楼层
本帖最后由 lkk0063 于 2022-9-5 16:21 编辑
zjdh 发表于 2022-9-5 15:52
你确定“OUT”文件中“1、2、3、....”是这样的吗?“4、5”又放在哪列?

你好
这个应该是要照编号 1~5 放入,只是我忘记改了
0.jpg
回复

使用道具 举报

发表于 2022-9-5 18:21 | 显示全部楼层    本楼为最佳答案   
数据不多,用复制黏贴就可以啦。
Private Sub CommandButton2_Click()
    Set WK = Workbooks.Open(ThisWorkbook.Path & "\Out.Xlsm")
    With WK.Sheets("BB")
        W = .[A65536].End(3).Row
        If W < 6 Then W = 6
        .Cells(W, 1) = Split([G1], "-")(0)
        .Cells(W, 2) = Year([C1])
        .Cells(W, 3) = [C1]
        .Cells(W, 4) = [E1]
        For i = 3 To 17
            Set C = .Cells.Find(Cells(i, "A").Value, lookat:=xlWhole)
            CL = C.Column
            Range(Cells(i, "F"), Cells(i, "J")).Copy .Cells(W, CL)
        Next
    End With
    WK.Close True
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-2 22:13 , Processed in 0.483325 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表