【发布时间】:2019-06-01 21:05:16
【问题描述】:
【问题讨论】:
标签: excel vba excel-2007
【问题讨论】:
标签: excel vba excel-2007
以下代码假定您有两个单独的选项卡,SRC 和 DST,并且数据范围从第一个单元格开始。一步完成:
Public Sub CopyAlternate()
Dim i As Long
i = 2
While Len(Sheets("SRC").Cells(i, 1).Value) > 0
Sheets("DST").Cells(i / 2 + 1, 1).Value = Sheets("SRC").Cells(i, 1).Value
Sheets("DST").Cells(i / 2 + 1, 2).Value = Sheets("SRC").Cells(i + 1, 1).Value
i = i + 2
Wend
End Sub
【讨论】:
你可以拿下这段代码,调整自己的口味:
Sub alternate()
Dim i As Integer
Dim j As Integer
Dim n As Integer
i = 0
j = 0
n = 0
With ActiveSheet
For Each c In .Range("A4:A16")
.Cells(20 + j, 1 + i).Value = c.Value
If n = 0 Or n Mod 2 = 0 Then
i = 1
j = j
Else
i = 0
j = j + 1
End If
n = n + 1
Next c
End With
End Sub
【讨论】: