选择第一个单元格中具有数值的行(A列)

时间:2015-07-22 11:56:23

标签: excel-vba vba excel

我正在使用Excel VBA尝试在我的电子表格中选择一系列行,这些行位于最后一行的下方,在A列中有一个数值。行40是我需要选择的位置,但此位置将更改。如何根据非数值执行选择。目前,我正在选择行范围并使用以下

删除它们
Rows("40:40").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp

2 个答案:

答案 0 :(得分:2)

Dim LastRow as Integer

LastRow = ActiveSheet.UsedRange.Rows.Count    

For row = 2 To LastRow
    If Not IsNumeric(Cells(row, 1)) Then
        row = row+1
        Rows(row).Select
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlUp
    End If
Next row

答案 1 :(得分:0)

最终结果。

    Dim LastRow As Integer
    LastRow = ActiveSheet.UsedRange.Rows.Count

'In this instance I am starting from row 6.
For Row = 6 To LastRow
    If Not IsNumeric(Cells(row, 1)) Then

        Rows(Row & ":" & Row).Select
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlUp
    End If
Next Row