1

我只想复制运行宏的任何工作簿的最后一张工作表的值(不是公式)(我不知道工作表的名称或工作表的数量),如果 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
4

1 回答 1

0

此修改会满足您的需要吗?

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
于 2013-04-28T10:14:18.713 回答