Excel 删除创建的最后一列中的单元格值

Excel 删除创建的最后一列中的单元格值,excel,vba,Excel,Vba,我一直在编写一个代码,复制最后一列并插入一个新列,复制其公式和格式。但是,我需要在创建的新列中删除行6到24的单元格值,然后从56到78。我找不到引用这些单元格的方法来删除它们的值,有人能帮我吗?我的代码如下: Sub Copy_Column() Dim LastCol As Integer With Worksheets("BO_Corretora") LastCol = .Cells(4, .Columns.Count).End(xlToLeft).Column

我一直在编写一个代码,复制最后一列并插入一个新列,复制其公式和格式。但是,我需要在创建的新列中删除行
6
24
的单元格值,然后从
56
78
。我找不到引用这些单元格的方法来删除它们的值,有人能帮我吗?我的代码如下:

Sub Copy_Column()
   Dim LastCol As Integer
   With Worksheets("BO_Corretora")
       LastCol = .Cells(4, .Columns.Count).End(xlToLeft).Column
       Columns(LastCol).Copy
       Columns(LastCol + 1).PasteSpecial Paste:=xlPasteFormats
       Columns(LastCol + 1).PasteSpecial Paste:=xlPasteFormulas
   End With
End Sub

这就是你想要的吗

Sub Copy_Column()
    Dim LastCol As Integer
    Dim NewCol As String

    With Worksheets("BO_Corretora")
        LastCol = .Cells(4, .Columns.Count).End(xlToLeft).Column
        .Columns(LastCol).Copy
        .Columns(LastCol + 1).PasteSpecial Paste:=xlPasteFormats
        .Columns(LastCol + 1).PasteSpecial Paste:=xlPasteFormulas

        '~~> Get the Column Letter of the new column
        NewCol = Split(.Cells(, LastCol + 1).Address, "$")(1)

        '~~> Range would be like Range("A6:A24,A56:A78")
        .Range(NewCol & "6:" & NewCol & "24," & _
               NewCol & "56:" & NewCol & "78").ClearContents
    End With
End Sub

您可以使用
intersect
。这使要删除的行易于阅读,并且可以将它们存储在常量中,以便在需要时进行编辑

Sub Copy_Column()
    Dim LastCol As Integer
    Dim NewCol As String

    With Worksheets("BO_Corretora")
        LastCol = .Cells(4, .Columns.Count).End(xlToLeft).Column
        .Columns(LastCol).Copy
        .Columns(LastCol + 1).PasteSpecial Paste:=xlPasteFormats
        .Columns(LastCol + 1).PasteSpecial Paste:=xlPasteFormulas

        Intersect(.Columns(LastCol + 1), .Range("6:24,56:78")).ClearContents
    End With
End Sub