答:alt+f11,打开VBE窗口,插入一个模块,复制宏代码。代码如下:
Sub Demo()
Dim MyRng As Range
Dim DesRng As Range, cell As Range
Set MyRng = Range("B2,B3,B7:G7")
Set DesRng = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For Each cell In MyRng
DesRng = cell
Set DesRng = DesRng.Offset(0, 1)
Next
End Sub
回到工作表中,插入一个表单控件按钮,连接到宏“Demo”,就可以使用了。
Sub 宏1()
Dim i As Integer
NextRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row + 1
i = NextRow
Sheet1.Cells(i, 1) = Sheet2.Cells(1, 1) ‘i确保了每次另起一行,修改cells中的参数设置需要对应的数据。
End Sub
若有不明白可以发附件xxqlong@163.com
加按钮简单,直接插入控件,指定该控件为上述宏即可。