我需要将备用行的数据(如D1 + D2)附加到excel中,请告诉我如何才能这样做
我有很大的excel,我正在寻找一个VBA,以便我可以将奇数行数据追加到偶数行并开发奇数行。
Surgical Surgical
10 $1,800 Unit 8/5/2011 unit
Surgical Surgical
10 $4,000 Unit 9/2/2011 unit
Surgical Surgical
10 $2,000 Unit 8/12/2011 unit
Surgical Surgical
10 $1,250 Unit 8/12/2011 unit
Surgical Surgical
10 $1,517 Unit 8/19/2011 unit
Surgical Surgical
10 $1,250 Unit 8/19/2011 unit
Surgical Surgical
10 $2,000 Unit 8/12/2011 unit
Surgical Surgical
10 $2,200 Unit 8/19/2011 unit
Surgical Surgical
10 $0 Unit 8/19/2011 unit
Surgical Surgical
10 $1,251 Unit 8/12/2011 unit
Surgical Surgical
10 $1,500 Unit 8/12/2011 unit
Surgical Surgical
10 $1,001 Unit 9/1/2011 unit
这些是在两个单元格和我的魔杖中将数据添加到上一个 请帮帮我
提前致谢
答案 0 :(得分:0)
我这样做只是使用这样的excel函数(假设您的原始数据在A列中):
=IF(MOD(ROW(),2)=1,A1&" "&A2,"")
应将其复制到原始数据旁边的任何列上。然后对包含此公式的列执行过滤器(在macintosh上执行命令+ shift + F,在Windows机器上不同)并将其设置为仅显示空行并删除它们。
如果你想在VBA中这样做
假设数据在A1:A10 范围内:
Sub mergeAndDelete()
Dim r As Range
Set r = Range("A1:A10") 'set the range the data resides in
For i = 1 To r.Rows.Count 'merge step
If i Mod 2 = 1 Then 'this checkes to see if i is odd
r.Cells(i, 1).Offset(0, 1).Value = r.Cells(i, 1).Value & " " & r.Cells(i + 1, 1).Value
End If
Next i
For i = r.Rows.Count To 1 Step -1
' Check if i is even and delete the row in the next line
If i Mod 2 = 0 Then
r.Cells(i, 1).EntireRow.Delete
End If
Next i
End Sub
此外,这会将偶数行添加到奇数行(基于您提供的示例 - 这与您实际所说的所需内容不同。)如果需要,修改if
语句。