|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
在这里,代码如下
- Sub 转换()
- Dim irow As Long, i As Long, j As Long, arr1, arr2, k As Long
- Dim ws1 As Worksheet, ws2 As Worksheet
- Set ws1 = Sheets("Sheet1")
- Set ws2 = Sheets("Sheet2")
- k = 1
- ws1.Activate
- irow = Cells(Rows.Count, 5).End(xlUp).Row
- arr1 = ws1.Range("A2:P" & irow)
- ReDim arr2(1 To 1000000, 1 To 15)
- For i = 1 To irow - 1
- If arr1(i, 15) <> "" Then
- For j = 1 To 15
- arr2(k, j) = arr1(i, j)
- Next
- If arr1(i, 16) <> "至今" Then
- Do While arr2(k, 15) <= arr1(i, 16)
- k = k + 1
- For j = 1 To 14
- arr2(k, j) = arr1(i, j)
- Next
- arr2(k, j) = arr2(k - 1, j) + 1
- Loop
- Else
- Do While arr2(k, 15) <= 2020
- k = k + 1
- For j = 1 To 14
- arr2(k, j) = arr1(i, j)
- Next
- arr2(k, j) = arr2(k - 1, j) + 1
- Loop
- End If
- End If
- Next
- ws2.Activate
- Range("A2").Resize(k, 15) = arr2
- End Sub
复制代码
你要处理的表 表格名改成“Sheet1”,结果表 表格名改为“Sheet2” |
|