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

前端 未结 4 1031
感情败类
感情败类 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:00

    Something like this might work...

    Sub Macro16()
    
        Dim ARow As Long, JRow As Long, ws1 As Worksheet
        ws1 = Sheets("NAME OF SHEET WITH DATA")
        ARow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row + 1
        ws1.Range("$A$1:$R$" & ARow).AutoFilter Field:=12, Criteria1:="Sheets"
        JRow = ws1.Range("J" & ws1.Rows.Count).End(xlUp).Row + 1
        ws1.Range("J" & JRow).FormulaR1C1 = "=RIGHT(RC[1],3)"
        ws1.Range("J" & JRow).FillDown
    End Sub
    
    0 讨论(0)
  • 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
    

          

    0 讨论(0)
  • 2020-12-06 20:09

    Untested but:

    Sub Macro16()
    
        With ActiveSheet.Range("A1").CurrentRegion
            .AutoFilter field:=12, Criteria1:="Sheets"
            If .Columns(1).SpecialCells(xlCellTypeVisible).count > 1 Then
                With .Columns(10)
                    .Resize(.rows.count - 1).offset(1).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=RIGHT(RC[1],3)"
                End With
            End If
        End With
    
    End Sub
    
    0 讨论(0)
  • 2020-12-06 20:13
    Sub FirstVisibleCell()
        With Worksheets("You Sheet Name").AutoFilter.Range
           Range("A" & .Offset(1, 0).SpecialCells(xlCellTypeVisible)(1).Row).Select
        End With
    End Sub
    
    0 讨论(0)
提交回复
热议问题