Sub MoveDirection() '定义变量 Dim rg As Range Dim i As Long '定义移动方向和移动距离 Dim MoveDirection As Integer Dim MoveRange As Integer
'设置移动方向以及移动距离 MoveDirection = 1 '向下移动 MoveRange = 2 '要移动的单元格数量
'Set rg等于某一列的指定范围 Set rg = Range("A1:A10")
For i = 1 To rg.Count '如果当前单元格不是rg中的最后一个单元格,则继续移动 If i <> rg.Count Then ' SendKeys "{ENTER}" ActiveCell.Offset(MoveDirection * MoveRange, 0).Activate '移动单元格 '否则,跳出循环 Else Exit For End If Next i
End Sub
运行Macro,可以在指定范围内按照所需方向移动单元格。此示例中,代码指定了在列A1:A10中向下移动两个单元格。可以根据需要调整移动方向和范围,以满足不同的需求。
上一篇:按下回车键再次点击按钮