【发布时间】:2023-02-02 05:31:23
【问题描述】:
I can't figure it out how to replace the value of a range after apply autofilter
my code below
Dim ws1 As Worksheet
Dim myname As String
Dim LastRow As Double
Dim LastRow2 As Double
myname = "Inventory"
Set ws1 = Sheets(myname)
ws1.Activate
ws1.Cells(1, 1).Select
' Find the last row
LastRow = ws1.Range("A1").CurrentRegion.Rows.Count
'select the table we are gonna work with
ws1.Range("A1:Q" & LastRow).Select
'filter table
Selection.AutoFilter Field:=6, Criteria1:="Online"
'Find the last row
LastRow2 = ws1.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1
' I want to select only the visible rows from column H after auto filter
'h1 is header cell
ActiveSheet.Range("H2:H" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.Copy ' to remove formulas
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("H1:H" &
LastRow).SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeBlanks).Value ="My new
text here"
the above code errors out, it says cant find the cells
Any ideas how I can do it?
-
I was able to edit the data after the autofilter was applied with this line ws1.AutoFilter.Range.Columns(8).SpecialCells(xlCellTypeVisible).Value = "En ligne"
标签: excel vba autofilter