过滤掉特定列的空白

时间:2014-06-04 12:36:01

标签: vba excel-vba excel

我想知道是否有办法在VBA中运行宏来过滤掉特定列的空白。该列当前在单元格中具有-1或空白。我试图添加一个宏,以便它删除空白,只留下单元格中的-1。谢谢。

I provided a picture of the column that I am trying to filter showing how there are blanks and non blanks.

这是我试图运行此宏的代码。

enter image description here

1 个答案:

答案 0 :(得分:1)

O.K。以下是 Z 列中空白的示例。这些行将被隐藏而不是删除。

Sub HideSome()
    Dim rHide As Range, col As String
    col = "Z"
    Set rHide = Intersect(Range(col & ":" & col), ActiveSheet.UsedRange).Cells.SpecialCells(xlCellTypeBlanks)
    rHide.EntireRow.Hidden = True
End Sub

修改#1

这是一个使用正确的标签和正确的列的版本:

Sub HideSome()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = ActiveSheet
    Set s2 = Sheets("Current")
    Dim rHide As Range, col As String
    col = "Z"
    s2.Activate
    Set rHide = Intersect(Range(col & ":" & col), ActiveSheet.UsedRange).Cells.SpecialCells(xlCellTypeBlanks)
    rHide.EntireRow.Hidden = True
    s1.Activate
End Sub

我们转到带有数据的标签.....隐藏行....然后返回......