【问题标题】:VBA First visible cell selection above header in after filtering过滤后标题上方的VBA第一个可见单元格选择
【发布时间】:2014-11-01 23:03:03
【问题描述】:

我需要 VBA 代码方面的帮助。我对 VBA 很陌生,但无法找到解决方案来解决过滤后在标题上方、列中选择第一个可见单元格的问题。我想选择此单元格以将其值设置为“x”,然后我需要为表中的每个过滤行输入“x”。 你知道如何通过选择 BK 列中的可见单元格并在其中输入“x”来简化操作吗?此列只有空白单元格。

任何帮助将不胜感激。

我的代码如下所示:

Sub Filter_and_insert()
'
' Filter_and_insert Makro
'

 'Select an active worksheet

    Sheets("DANE PIPELINE 29.10").Select

 ' First filter I use for data

    ActiveSheet.Range("$A$3:$BQ$4773").AutoFilter Field:=40, Criteria1:=Array( _
        "C.O.R.", "Contract", "Positive Quote", "Quote", "Selling"), Operator:= _
        xlFilterValues

 ' Second filter I use for data

    ActiveSheet.Range("$A$3:$BQ$4773").AutoFilter Field:=25, Criteria1:= _
        "Not assigned"

 ' Here I need to select first visible cell above header after filtering and set its 
 ' value to  "x".
 ' Range ("BK36") is only for this current data and it will be different for 
 ' other data so thats why I need to find first visible cell.

    Range("BK36").Select
    ActiveCell.Value = "x"

  ' Here I am selecting all filtered cells in a row and fill them with "x"

    ActiveCell.Offset(0, -20).Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(0, 20).Select
    Range(Selection, Selection.End(xlUp)).Select
    Selection.FillDown

   ' Reset filters

            Selection.AutoFilter Field:=40
            Selection.AutoFilter Field:=25


End Sub

非常感谢您提前提供的所有帮助。

【问题讨论】:

    标签: excel vba filtering


    【解决方案1】:

    这将在 BK

    列的每个可见单元格中放置一个 "x"
    Sub MarkX()
        Dim rX As Range
        Set rX = Intersect(ActiveSheet.UsedRange, Range("BK:BK")).Cells.SpecialCells(xlCellTypeVisible)
        rX.Value = "x"
    End Sub
    

    【讨论】:

    • 非常感谢您的回复。它对我有用。不得不对其进行一些修改,然后我想到了一个想法并写了这个:“Range([BK4],Cells(Rows.Count,“BK”)).SpecialCells(xlCellTypeVisible)(1).Select”。您需要使用标题上方的第一个隐藏单元格,在我的情况下为 BK4。再次感谢您的帮助。
    猜你喜欢
    • 2017-08-21
    • 2018-07-02
    • 1970-01-01
    • 2012-12-19
    • 2014-03-14
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多