Excel精英培训网

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

[已解决]请在下面代码增加arr和转置函数

[复制链接]
发表于 2012-12-25 13:58 | 显示全部楼层 |阅读模式
本帖最后由 hcy1185 于 2012-12-25 14:04 编辑

Sub 标题写入字典再填到单元格()
    Dim d As Object, lie As Integer, j As Integer
    Set d = CreateObject("Scripting.Dictionary")
    Sheet1.Activate
    lie = Range("IV1").End(xlToLeft).Column
    For j = 1 To lie
        d(Cells(1, j).Value) = Cells(1, j)
    Next j
    Sheet2.Range("a1").Resize(1, d.Count) = d.keys 'd.items
    Set dic = Nothing 'd.RemoveAll
End Sub
最佳答案
2012-12-25 14:42
  1. Sub 标题写入字典再填到单元格()
  2.      Dim d As Object, lie As Integer, j As Integer
  3.      Dim arr
  4.      Set d = CreateObject("Scripting.Dictionary")
  5.      Sheet1.Activate
  6.      arr = Range(Cells(1, Range("IV1").End(xlToLeft).Column), Range("iv1"))
  7.      For j = 1 To UBound(arr, 2)
  8.               d(arr(1, j)) = arr(1, j)
  9.      Next j
  10.      '一列输出
  11.      Sheet2.Range("a1").Resize(d.Count, 1) = Application.Transpose(d.keys)
  12.      '一行输出
  13.      'Sheet2.Range("a1").Resize(1, d.Count) = d.keys
  14.      
  15.      Set d = Nothing 'd.RemoveAll
  16. End Sub
复制代码
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-12-25 14:07 | 显示全部楼层
神马情况?
application.transpose()
转置。
回复

使用道具 举报

 楼主| 发表于 2012-12-25 14:15 | 显示全部楼层
hwc2ycy 发表于 2012-12-25 14:07
神马情况?
application.transpose()
转置。

如果把
sheet1.range("a1:a" & lie)写入arr
现在的代码如何修改?
谢谢!!!
回复

使用道具 举报

发表于 2012-12-25 14:28 | 显示全部楼层
arr = Sheet1.Range("a1:a" & ie)
回复

使用道具 举报

 楼主| 发表于 2012-12-25 14:32 | 显示全部楼层
hwc2ycy 发表于 2012-12-25 14:28
arr = Sheet1.Range("a1:a" & ie)

d(Cells(1, j).Value) = Cells(1, j)
怎么修改?
回复

使用道具 举报

发表于 2012-12-25 14:34 | 显示全部楼层
d(arr(1,j))=arr(1,j)
回复

使用道具 举报

发表于 2012-12-25 14:42 | 显示全部楼层    本楼为最佳答案   
  1. Sub 标题写入字典再填到单元格()
  2.      Dim d As Object, lie As Integer, j As Integer
  3.      Dim arr
  4.      Set d = CreateObject("Scripting.Dictionary")
  5.      Sheet1.Activate
  6.      arr = Range(Cells(1, Range("IV1").End(xlToLeft).Column), Range("iv1"))
  7.      For j = 1 To UBound(arr, 2)
  8.               d(arr(1, j)) = arr(1, j)
  9.      Next j
  10.      '一列输出
  11.      Sheet2.Range("a1").Resize(d.Count, 1) = Application.Transpose(d.keys)
  12.      '一行输出
  13.      'Sheet2.Range("a1").Resize(1, d.Count) = d.keys
  14.      
  15.      Set d = Nothing 'd.RemoveAll
  16. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-18 19:40 , Processed in 0.420095 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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