Select first visible cell directly beneath the header of a filtered column

前端 未结 4 1041
感情败类
感情败类 2020-12-06 19:34

I am trying to select the first visible cell directly beneath the header of a filtered column. The code I am getting is as below, but I have to problems with this code. Fi

4条回答
  •  渐次进展
    2020-12-06 20:08

    I prefer non-destructive methods of determining whether there are visible cells to work with after a filtering operation. Since you are filling in column J with a formula, there is no guarantee that column J contains any values tat can be counted with the worksheet's SUBTOTAL function (SUBTOTAL does not count rows hidden by a filter) but the formula you are planning to populate into column J references column K so there must be something there.

    Sub Macro16()
        With ActiveSheet
            If .AutoFilterMode Then .AutoFilterMode = False
            With .Cells(1, 1).CurrentRegion
                .Columns(12).AutoFilter Field:=1, Criteria1:="Sheets"
                With .Resize(.Rows.Count - 1, 1).Offset(1, 9)
                    If CBool(Application.Subtotal(103, .Offset(0, 1))) Then
                        .SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=RIGHT(RC[1],3)"
                    End If
                End With
                .Columns(12).AutoFilter Field:=1
            End With
        End With
    End Sub
    

          

提交回复
热议问题