TTEP.CN > 软件 >
自己编写宏让Excel单元格或者整列左移右移
办公时需要将某个单元格左移右移,该如何操作呢?虽然有些方法可以实现,但是都不如宏来的实际快速。下面,我就分享一下宏代码,以后使用的时候直接执行就可以啦。
①单击菜单栏--视图--宏--查看宏。

②弹出宏的界面,输入宏的名称,这里为了便于记忆,我们命名为向左移动一列,然后点击创建按钮。

③在新出现的界面中,输入代码,也就是程序语言,我已经写好了,大家直接复制即可。
Application.ScreenUpdating = False
x = Selection.Column
If x >= 1 Then
Columns(x).Cut
Columns(x - 1).Insert
Application.ScreenUpdating = True
End If

④退出编辑状态,选中单元格或者整列,执行宏即可。下面,我把向右移动一列的代码也给大家。
Application.ScreenUpdating = False
x = Selection.Column
If x < 256 Then
Columns(x).Cut
Columns(x + 2).Insert
End If
Application.ScreenUpdating = True
End Sub
①单击菜单栏--视图--宏--查看宏。

②弹出宏的界面,输入宏的名称,这里为了便于记忆,我们命名为向左移动一列,然后点击创建按钮。

③在新出现的界面中,输入代码,也就是程序语言,我已经写好了,大家直接复制即可。
Application.ScreenUpdating = False
x = Selection.Column
If x >= 1 Then
Columns(x).Cut
Columns(x - 1).Insert
Application.ScreenUpdating = True
End If

④退出编辑状态,选中单元格或者整列,执行宏即可。下面,我把向右移动一列的代码也给大家。
Application.ScreenUpdating = False
x = Selection.Column
If x < 256 Then
Columns(x).Cut
Columns(x + 2).Insert
End If
Application.ScreenUpdating = True
End Sub
- 上一篇:Excel中将整数转变为年月日形式
- 下一篇:Excel中Countif函数初步讲解
- 最近发表
- 赞助商链接