Excel精英培训网

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

[已解决]VBA代码求助

[复制链接]
发表于 2021-8-25 14:31 | 显示全部楼层 |阅读模式
我编写一段代码,在汇总表里汇总各SHEET里的数据,但最终都是数值 ,我想要带链接的,请帮助看一下怎么改,谢谢了。


Sub DL()
Dim arr1(), arr2()
For Each sh In Sheets
    If sh.Name <> "DL" Then
        With Sheets("DL")
            .Cells(4 + N, 5) = sh.[F15]
            .Cells(4 + N, 6) = sh.[H15]
            .Cells(4 + N, 7) = sh.[J15]
            .Cells(4 + N, 8) = sh.[L15]
            .Cells(4 + N, 9) = sh.[N15]
            .Cells(4 + N, 10) = sh.[P15]
            .Cells(4 + N, 11) = sh.[R15]
            .Cells(4 + N, 12) = sh.[T15]
            .Cells(4 + N, 13) = sh.[V15]
        End With
        N = N + 1
        sh.Name = sh.[D8]
End If
Next
End Sub

最佳答案
2021-8-25 18:13
Sub DL()
Dim n
For Each sh In Sheets
    If sh.Name <> "DL" Then
        With Sheets("DL")
            .Cells(4 + n, 5) = "=" & sh.Name & "!f15"
            .Cells(4 + n, 6) = "=" & sh.Name & "!h15"
            .Cells(4 + n, 7) = "=" & sh.Name & "!j15"
            .Cells(4 + n, 8) = "=" & sh.Name & "!l15"
            .Cells(4 + n, 9) = "=" & sh.Name & "!n15"
            .Cells(4 + n, 10) = "=" & sh.Name & "!p15"
            .Cells(4 + n, 11) = "=" & sh.Name & "!r15"
            .Cells(4 + n, 12) = "=" & sh.Name & "!t15"
            .Cells(4 + n, 13) = "=" & sh.Name & "!v15"
        End With
        n = n + 1
        sh.Name = sh.[D8]
End If
Next
End Sub
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2021-8-25 14:55 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2021-8-25 16:26 | 显示全部楼层
回复

使用道具 举报

发表于 2021-8-25 18:13 | 显示全部楼层    本楼为最佳答案   
Sub DL()
Dim n
For Each sh In Sheets
    If sh.Name <> "DL" Then
        With Sheets("DL")
            .Cells(4 + n, 5) = "=" & sh.Name & "!f15"
            .Cells(4 + n, 6) = "=" & sh.Name & "!h15"
            .Cells(4 + n, 7) = "=" & sh.Name & "!j15"
            .Cells(4 + n, 8) = "=" & sh.Name & "!l15"
            .Cells(4 + n, 9) = "=" & sh.Name & "!n15"
            .Cells(4 + n, 10) = "=" & sh.Name & "!p15"
            .Cells(4 + n, 11) = "=" & sh.Name & "!r15"
            .Cells(4 + n, 12) = "=" & sh.Name & "!t15"
            .Cells(4 + n, 13) = "=" & sh.Name & "!v15"
        End With
        n = n + 1
        sh.Name = sh.[D8]
End If
Next
End Sub
回复

使用道具 举报

发表于 2021-8-25 18:15 | 显示全部楼层
只为说明问题,其实那几句可以用循环的。
回复

使用道具 举报

 楼主| 发表于 2021-8-25 21:01 | 显示全部楼层
高 发表于 2021-8-25 18:15
只为说明问题,其实那几句可以用循环的。

感谢大神,完美解决!
回复

使用道具 举报

 楼主| 发表于 2021-8-31 15:11 | 显示全部楼层
高 发表于 2021-8-25 18:13
Sub DL()
Dim n
For Each sh In Sheets

表A,表B为两个不同的EXCEL文件都含有多个sheet,相同点两个文件里的部分sheet名称相同,要建立两个文件之间的sheet链接,具体如下,请大神帮助如何建立起下列关系,程序怎么写,多谢。

D4=D6  
D5=D7
D6=D8
I6=J8
H25=AE1
I25=AF1
J25=AB1
M25=Z1
C39:D49=X18:Y28

T79=U31
T81=U32
T84=U33
I110:I119=Z18:Z27
P110=K45
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 23:12 , Processed in 0.143801 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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