删除单元格行,但不删除整行

时间:2012-08-24 13:29:09

标签: excel excel-vba vba

我只需要删除7B:7G,而只留下7A。如何使用excel VBA执行此操作?

以下是我现在的代码:

Option Explicit

Sub Import()

    Dim lastrow As Long
    Dim wsIMP As Worksheet 'Import
    Dim wsTOT As Worksheet 'Total
    Dim wsSHI As Worksheet 'Shipped
    Dim wsEST As Worksheet 'Estimate
    Dim wsISS As Worksheet 'Issued
    Dim cel As Range

    Set wsIMP = Sheets("Import")
    Set wsTOT = Sheets("Total")
    Set wsSHI = Sheets("Shipped")
    Set wsEST = Sheets("Estimate")
    Set wsISS = Sheets("Issued")

    With wsIMP

        wsIMP.Range("E6").Cut wsIMP.Range("E5")
        wsIMP.Range("B7:G7").Delete (xlShiftUp)

    End With

End Sub

2 个答案:

答案 0 :(得分:3)

您需要做的是删除范围B7:G7,向左或向上移动单元格(取决于要求):

range("B7:G7").delete(xlShiftToLeft)

range("B7:G7").delete(xlShiftUp)

答案 1 :(得分:2)

使用With时,不应在2个中间行中提及wsIMP。将您的代码更改为:

With wsIMP

    .Range("E6").Cut .Range("E5")
    .Range("B7:G7").Delete (xlShiftUp)

End With

还注意到第二范围表示法。这是B7:G7而不是7B:7G