|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 转换()
- Dim vData As Variant, nRow As Integer
- Dim vFill As Variant, nFill As Integer
- Dim vKey As Variant, nKey As Integer
- vData = [A1:B2]
- ReDim vFill(1 To 2, 1 To 1)
- For nRow = 1 To UBound(vData)
- vKey = Split(vData(nRow, 2), ",")
- For nKey = 0 To UBound(vKey)
- nFill = nFill + 1
- ReDim Preserve vFill(1 To 2, 1 To nFill)
- vFill(1, nFill) = vData(nRow, 1)
- vFill(2, nFill) = vKey(nKey)
- Next
- Next
- [C1:D1].Resize(nFill) = Application.WorksheetFunction.Transpose(vFill)
- End Sub
复制代码 |
|