首页 > 编程语言 > 详细

20170814xlVBA部分代号收盘价转置

时间:2017-08-15 09:15:42      阅读:240      评论:0      收藏:0      [点我收藏+]

原始数据:

技术分享

转置效果:

技术分享

 

 

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部分代号收盘价转置

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!