|
本帖最后由 zxsea_7426 于 2023-4-13 10:26 编辑
修改两行代码就好,去除删除,并输出到最后一行就可以了。
- Sub test()
- With Sheets("长江1")
- R = .Cells(Rows.Count, "H").End(3).Row
- ar = .Range(.[a1], .Cells(R, "j"))
- ReDim arr(1 To UBound(ar), 1 To 6)
- For i = 3 To UBound(ar)
- If ar(i, 8) <> "" Then
- n = n + 1
- arr(n, 1) = n
- For j = 2 To 6
- arr(n, j) = ar(i, j)
- Next j
- For j = 4 To 6
- ar(i, j) = ar(i, j + 4): ar(i, j + 4) = ""
- Next j
- End If
- Next i
- .[a1].Resize(UBound(ar), UBound(ar, 2)) = ar
- End With
- With Sheets("沙滩1")
- ' .Cells.ClearContents
- ' Sheets("长江1").[a2].Resize(1, 6).Copy .[a1]
- ' .[a2].Resize(n, 6) = arr
- lst_row = .Cells(Rows.Count, 1).End(3).Row '最后一行行号
- If lst_row > 1 Then '最后一行大于1行说明该表已有数据,直接在最后一行下一行输出
- .Cells(lst_row + 1, 1).End(3).Offset(1, 0).Resize(n, 6) = arr
- Else '最后一行低于2行说明该表没有数据,重新复制表头并输出数据
- Sheets("长江1").[a2].Resize(1, 6).Copy .[a1]
- .[a2].Resize(n, 6) = arr
- End If
- End With
- Erase ar
- Erase arr
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|