如何使用VBA或使用条件语句在Excel中复制行3或4次,然后将值从一个单元格复制并粘贴到另一个单元格。
这就是数据的样子
这就是我想结束的方式。
更新:在下面的代码中我想复制合并到行,col no 176,177,178,179,180它很好但删除了1 col和176 col之间的所有列。
Sub SortMacro()
Dim SourceSheet As Worksheet
Dim OutSheet As Worksheet
Set SourceSheet = ActiveSheet
Set OutSheet = Sheets.Add
With SourceSheet
Out_i = 1
For r = 1 To .Cells(Rows.Count, 176).End(xlUp).Row
For i = 176 To 180 'or For each i in Array(3,4,5)
OutSheet.Cells(Out_i, 1) = .Cells(r, 1)
OutSheet.Cells(Out_i, 176) = .Cells(r, i)
Out_i = Out_i + 1
Next
Next
End With
End Sub
答案 0 :(得分:0)
MyRange.Offset(RowOffset, ColumnOffset).Value = MyRange.Value
答案 1 :(得分:0)
打开VBA edior(Alt-F11)。创建新的VBA模块(右键转到VBA项目,插入,模块)。将此代码复制到新模块。运行代码(选择包含源数据的工作表,然后单击VBA代码文本中的任意位置并按F5)。
Sub SortMacro()
Dim SourceSheet As Worksheet
Dim OutSheet As Worksheet
Set SourceSheet = ActiveSheet
Set OutSheet = Sheets.Add
With SourceSheet
Out_i = 1
For r = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To 5 'or For each i in Array(3,4,5)
OutSheet.Cells(Out_i, 1) = .Cells(r, 1)
OutSheet.Cells(Out_i, 2) = .Cells(r, i)
Out_i = Out_i + 1
Next
Next
End With
End Sub