Excel精英培训网

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

[已解决](求助)如何用代码从表2中提取数据到表1来?

[复制链接]
发表于 2012-11-15 07:29 | 显示全部楼层 |阅读模式
如附件 提数附件.rar (80.1 KB, 下载次数: 5)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-11-15 07:51 | 显示全部楼层
代码中没有判断第一行中的内容是否是合法的列标,
所以第一行的内容,只能自己手工输入时校验好!
如附件中的数据,当代码运行到 E1 时,则会提示错误!!

  1. Sub cc()
  2. Dim Lx As Integer, L As Integer, Hx As Integer
  3. Dim Co As String
  4.   L = 15
  5.   With Sheets("Sheet2")
  6.     For Lx = 1 To Range("A1").End(xlToRight).Column
  7.       Co = Cells(1, Lx).Value
  8.       Hx = .Cells(1, Co).End(xlDown).Row
  9.       Cells(1, L).Resize(Hx).Value = .Range(.Cells(1, Co), .Cells(Hx, Co)).Value
  10.       L = L + 1
  11.     Next
  12.   End With
  13. End Sub
复制代码

评分

参与人数 1 +1 收起 理由
dfshm + 1 赞一个!

查看全部评分

回复

使用道具 举报

发表于 2012-11-15 08:18 | 显示全部楼层    本楼为最佳答案   
本帖最后由 zjdh 于 2012-11-15 08:19 编辑


Sub TEST()
    For I = 1 To Range("A1").End(2).Column
        With Sheets(2)
            .Range(.Cells(1, Cells(1, I).Value), .Cells(.UsedRange.Rows.Count, Cells(1, I).Value)).Copy Cells(1, I + 14)
        End With
    Next
End Sub
提数附件.rar (87.07 KB, 下载次数: 13)

评分

参与人数 1 +1 收起 理由
dfshm + 1 很给力!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 14:54 , Processed in 1.014629 second(s), 18 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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