我需要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
非常感谢您提前提供所有帮助。
答案 0 :(得分:0)
这会在 BK
列中的每个可见单元格中放置" x"Sub MarkX()
Dim rX As Range
Set rX = Intersect(ActiveSheet.UsedRange, Range("BK:BK")).Cells.SpecialCells(xlCellTypeVisible)
rX.Value = "x"
End Sub