Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
插入和剪切列的VBA循环?_Vba_Excel - Fatal编程技术网

插入和剪切列的VBA循环?

插入和剪切列的VBA循环?,vba,excel,Vba,Excel,我不确定如何创建这个循环,所以我做了一个录制的宏。如何使其成为贯穿所有工作表的循环 Sheets("AT").Select Columns("F:F").Select Selection.Cut Columns("E:E").Select Selection.Insert Shift:=x1ToRight Columns("H:H").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlF

我不确定如何创建这个循环,所以我做了一个录制的宏。如何使其成为贯穿所有工作表的循环

Sheets("AT").Select
    Columns("F:F").Select
    Selection.Cut
    Columns("E:E").Select
    Selection.Insert Shift:=x1ToRight
    Columns("H:H").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("I:I").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("K:K").Select
    Selection.Cut
    Columns("J:J").Select
    Selection.Insert Shift:=x1ToRight

不能。在工作表上选择一个非活动工作表的单元格/区域,因此基本上有两种选择;或者。在循环中激活每个工作表,然后在该工作表上运行代码(不推荐),或者修改代码,以便(推荐)


列是否需要按该顺序完成?没有
G
?没有特定的顺序,也不需要G。我想你要找的是:
在工作表中的每个wsName
下一个wsName
,其中
wsName
被标注为工作表。你的
xlToRight
中有两个是
1
而不是
l
@BigBen谢谢,我也这么认为。发现这样的东西应该值得一个自动徽章或其他东西\。。。大声笑
Option Explicit

Sub Macro1()

    Dim w As Long

    For w = 1 To Worksheets.Count
        With Worksheets(w)
            .Columns("F:F").Cut
            .Columns("E:E").Insert Shift:=xlToRight

            .Columns("H:I").Insert Shift:=xlToRight

            .Columns("K:K").Cut
            .Columns("J:J").Insert Shift:=xlToRight
        End With
    Next w

End Sub