我需要帮助为Excel 2010编写VBA脚本(Windows 7)。
我有数以千计的条目设置如下:
Data ID Number1 (A1)
Data Article Name1 (A2)
Data ID Number2 (A3)
Data Article Name2 (A4)
Data ID Number 3 (A5)
Data Article Name 3 (A6)
Data ID Number 3 (A7)
Data Article Name 3 (A8)
=============
我需要它看起来像这样:
Data ID Number1 (A1) Data Article Name1 (B1)
Data ID Number2 (A2) Data Article Name2 (B2)
Data ID Number 3 (A3) Data Article Name3 (B3)
Data ID Number 4 (A4) Data Article Name4 (B4)
我需要能够将此作为自动过程,因为我有大量条目。
编辑更改了文章,使其更清晰一点!
答案 0 :(得分:0)
这会有用吗?如果您想要删除包含文章的原始行,则不确定您的问题。
Dim row
Dim lastRow
lastRow = 8
For row = lastRow To 2 Step -1
If row Mod 2 = 0 Then
' copy data
Cells(row - 1, 2) = Cells(row, 1).Value
' delete row
Cells(row, 1).EntireRow.Delete
End If
Next
答案 1 :(得分:0)
此宏将遍历A列中的所有单元格。如果单元格行是偶数,则该值将移动到B列(偏移量为(-1,1)。)然后将单元格添加到For循环完成后删除的范围。
Sub test()
Dim i As Range
Dim delrows As Range
For Each i In Intersect(ActiveSheet.UsedRange, Range("A:A"))
If (i.Row Mod 2) = 0 Then
i.Offset(-1, 1).Value = i.Value
If delrows Is Nothing Then
Set delrows = i
Else
Set delrows = Union(i, delrows)
End If
End If
Next i
delrows.EntireRow.Delete
End Sub
答案 2 :(得分:0)
这段代码有点简单,但应该做的诀窍
Sub Shift()
'Set to your first value you want shifted. In your example A2.
Range("A2").Select
Do
ActiveCell.Cut
ActiveCell.Offset(-1, 1).Select
ActiveSheet.Paste
ActiveCell.Offset(1, -1).Select
ActiveCell.EntireRow.Select
ActiveCell.Delete
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Value = "" And ActiveCell.Offset(-1, 0).Value = ""
End Sub
祝你有美好的一天!