|
行列转换。。。
- Sub ykcbf() '//2024.12.3
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- ReDim brr(1 To 10000, 1 To 100)
- m = 1: n = 2
- brr(1, 1) = "时间": brr(1, 2) = "型号"
- On Error Resume Next
- With Sheets("原表")
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(10, c)
- End With
- For j = 1 To UBound(arr, 2)
- If InStr(arr(2, j), "指标") Then k = k + 1: d1(k) = j
- Next
- For i = 3 To UBound(arr)
- s = arr(i, 2)
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(1, n) = arr(i, 2)
- End If
- Next
- For k = 1 To d1.Count
- c1 = d1(k)
- yf = arr(1, c1 + 2)
- If k = d1.Count Then c2 = c Else c2 = d1(k + 1) - 1
- For j = c1 + 2 To c2 Step 2
- If arr(2, j) <> Empty Then
- For i = 3 To UBound(arr)
- s = yf & "|" & arr(2, j)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = yf
- brr(m, 2) = arr(2, j)
- End If
- r = d(yf & "|" & arr(2, j))
- c = d(arr(i, 2))
- brr(r, c) = Val(arr(i, j))
- Next
- End If
- Next
- Next
- With Sheets("整理后")
- .UsedRange.Clear
- .[a1].Resize(1, n).Interior.Color = 49407
- With .[a1].Resize(m, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- .[c2].Resize(m - 1, n - 2).HorizontalAlignment = xlRight
- .[c2].Resize(m - 1, n - 2).NumberFormatLocal = "0.00"
- .Range("d:d,h:h,j:j").NumberFormatLocal = "0.0%"
- .Range("c:c,e:g,i:i").NumberFormatLocal = "0"
- ActiveWindow.DisplayZeros = False
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|