码迷,mamicode.com
首页 > 编程语言 > 详细

20170814xlVBA部分代号收盘价转置

时间:2017-08-15 10:10:51      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:for   bsp   cell   highlight   分代   variant   image   nbsp   scripting   

原始数据:

技术分享

转置效果:

技术分享

 

 

Sub TransformData()
    Dim Rng As Range
    Dim Arr As Variant
    Dim Dic As Object
    Dim dCode As Object
    Dim dDay As Object
    Set Dic = CreateObject("Scripting.Dictionary")
    Set dCode = CreateObject("Scripting.Dictionary")
    Set dDay = CreateObject("Scripting.Dictionary")
    With Sheets("WRESSTK")
        endrow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
        Set Rng = .Range("A2:C" & endrow)
        Arr = Rng.Value
        For i = LBound(Arr) To UBound(Arr)
            
            Key = Format(Arr(i, 1), "000000")
            dCode(Key) = ""
            
            Key = Format(Arr(i, 2), "yyyy-mm-dd")
            dDay(Key) = ""
            
            Key = Format(Arr(i, 1), "000000") & ";" & Format(Arr(i, 2), "yyyy-mm-dd")
            Dic(Key) = Arr(i, 3)
        Next i
    End With
    
    With Sheets("Result")
        i = 1
        For Each k In dCode.keys
            i = i + 1
            .Cells(i, 1).Value = "‘" & k
        Next k
        
        j = 1
        For Each k In dDay.keys
            j = j + 1
            .Cells(1, j).Value = "‘" & k
        Next k
        ‘Exit Sub
        For m = 2 To i
            For n = 2 To j
                Key = Format(.Cells(m, 1).Text) & ";" & Format(.Cells(1, n).Text, "yyyy-mm-dd")
                .Cells(m, n).Value = Dic(Key)
            Next n
        Next m
    End With
    
    Set Dic = Nothing
    Set dCode = Nothing
    Set dDay = Nothing
    Set Rng = Nothing
End Sub

  

 

20170814xlVBA部分代号收盘价转置

标签:for   bsp   cell   highlight   分代   variant   image   nbsp   scripting   

原文地址:http://www.cnblogs.com/nextseven/p/7363106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!