Excel 将值复制到最后一张图纸之后的新图纸,如果为空,则删除b列

Excel 将值复制到最后一张图纸之后的新图纸,如果为空,则删除b列,excel,vba,Excel,Vba,我只想复制运行宏的任何工作簿最后一页的值(而不是公式)(我不知道工作表的名称或工作表的数量),如果B列为空,则删除B列,并将此新工作表命名为“游戏”。这是我所拥有的,但它不起作用 Sub ArrumarTabela() ActiveSheet.Copy Cells.Copy Application.CutCopyMode = False ActiveSheet.Name = "Games" Range("A1").PasteSpecial Paste:=

我只想复制运行宏的任何工作簿最后一页的值(而不是公式)(我不知道工作表的名称或工作表的数量),如果B列为空,则删除B列,并将此新工作表命名为“游戏”。这是我所拥有的,但它不起作用

Sub ArrumarTabela()
    ActiveSheet.Copy
    Cells.Copy

    Application.CutCopyMode = False
    ActiveSheet.Name = "Games"
    Range("A1").PasteSpecial Paste:=xlPasteValues
    Application.ScreenUpdating = False

    ActiveSheet.Name = "Games"

    Dim cl As Range
    For Each cl In Range("$B$2:$B" & Range("$B$65536").End(xlUp).Row)
        If cl = "" Then cl.EntireColumn.Delete
    Next cl

    Range("C1").Select
    Selection.EntireColumn.Insert , CopyOrigin:=xlFormatFromLeftOrAbove

    Application.ScreenUpdating = True
End Sub

这项修改能满足您的需要吗

Sub ArrumarTabela()
    ActiveSheet.Copy 'this will create a new workbook and a new sheet with current

    With ActiveSheet
        .Name = "Games" 'change new sheets name

        .Cells.Copy 'copy all cells
        .Range("A1").PasteSpecial Paste:=xlPasteValues 'paste only values
        .ScreenUpdating = False

        lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row 'last row?

        Set cl = .Range("B2:B" & lastrow).Find("", lookat:=xlWhole) 'find a blank cell in a range

        If Not cl Is Nothing Then cl.EntireColumn.Delete 'delete column if blank exists

        .Range("C1").EntireColumn.Insert 'insert new column belfore column C

        .ScreenUpdating = True
    End With
End Sub

Application.CutCopyMode=False
这将清除剪贴板…那么您将如何粘贴?正如sid所说。您应该删除
CutCopyMode=False