【发布时间】: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
非常感谢您提前提供的所有帮助。
【问题讨论】: