|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test1()
- Dim data, results()
- Dim i As Long, j As Long, cnt As Long, s As String
- data = Range("L1", Cells(Rows.Count, "D").End(xlUp)).Value
- ReDim results(1 To UBound(data) * UBound(data, 2), 1 To 4)
- For j = 2 To UBound(data, 2)
- If Len(data(1, j)) Then s = data(1, j)
- data(1, j) = s
- Next
- For i = 3 To UBound(data)
- For j = 2 To UBound(data, 2)
- cnt = cnt + 1
- results(cnt, 1) = data(i, 1)
- results(cnt, 2) = data(1, j)
- results(cnt, 3) = data(2, j)
- results(cnt, 4) = data(i, j)
- Next
- Next
- With Range("N2")
- .CurrentRegion.Clear
- With .Resize(cnt, UBound(results, 2))
- .Borders.LineStyle = xlContinuous
- .HorizontalAlignment = xlCenter
- .Value = results
- End With
- End With
- Beep
- End Sub
复制代码 |
|