自动翻转

时间:2017-05-02 14:05:27

标签: vba excel-vba excel

我已经自动过滤了,我想选择不隐藏的行,如果只有一行我只能选择该行。

我坚持一句话,请帮助我,代码正在运行,但即使if语句为真,它也会转到else语句,我写的代码是

If ActiveCell.Value ="" Then
Else
    ActiveCell.EntireRow.Select

    If ActiveCell.Offset(1, 0).Value = "" then 
        Do Until ActiveCell.Offset(1, 0).EntireRow.Hidden = False
        Loop
    Else
        Range(Selection, Selection.End(xldown)).Select
    End if
    Selection.Copy
End if

1 个答案:

答案 0 :(得分:0)

要选择工作表中的每个可见和非空行,请使用以下内容:

Option Explicit

Sub SelectVisibleNonEmptyRows()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1") 'Enter your worksheet name here

    Dim lastRow As Long
    lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row

    ws.Range(ws.Rows(2), ws.Rows(lastRow)).SpecialCells(xlCellTypeVisible).EntireRow.Select
End Sub