|
本帖最后由 tuujjjj 于 2022-2-20 21:43 编辑
副本透视列.zip
(24.38 KB, 下载次数: 6)
这个问题用VBA数组加循环好解决好多,做了个Sub 代码1()
Dim arr, i, h
Dim dc As Object
Set dc = CreateObject("scripting.dictionary")
Range("E10").Resize(10000, 10000).Clear '清空将要做表的区域,E10是要做表的区域的左上角位,要修改请将全部E10修改成你想要的位置即可
arr = Range("B3", [C3].End(xlDown)) 'B3表1的第一个编码的位置,C3是是表1第一个店名的位置,如位置不一样请修改
For i = 1 To UBound(arr)
dc(arr(i, 1)) = ""
Next
Range("E10")(2, 1).Resize(dc.Count) = Application.Transpose(dc.keys)
For h = 1 To dc.Count
k = 0
For i = 1 To UBound(arr)
If arr(i, 1) = Range("E10")(1 + h, 1) Then
k = k + 1
Range("E10")(1 + h, 1)(1, k + 1) = arr(i, 2)
End If
Next
If p < k Then p = k
Next
Range("E10") = "编码"
For i = 1 To p
Range("E10")(1, 1 + i) = "序号" & i
Next
Range("E10").CurrentRegion.Borders.LineStyle = 1
Range("E10").CurrentRegion.HorizontalAlignment = xlCenter
End Sub
|
|