[英]VBA: Why will Autofilter not work when manual filter does? (Run-time error '1004': Method 'AutoFilter' of object 'Range' failed)
獲取以下代碼的運行時錯誤。
對於某些列,使用包含行1000等數據的數據轉儲。 從我在其他論壇上看到的內容來看,如果單元格附近沒有值,則autofilter將無法工作。 但是,當我將測試值放在更接近過濾器的位置時,它仍然無法工作。 手動過濾器正在同一范圍內工作。
CURrow = ActiveCell.Row
LASTrow = ActiveCell.SpecialCells(xlLastCell).Row
LASTcol = ActiveCell.SpecialCells(xlLastCell).Column
If LASTrow > CURrow Then
Columns("A").Insert Shift:=xlToRight
Range(Cells(CURrow + 1, 1), Cells(LASTrow, 1)).Value = "|"
Columns(1).HorizontalAlignment = xlCenter
Range(Cells(CURrow, 1), Cells(CURrow, LASTcol - 1)).AutoFilter
Rows(CURrow + 1).Select
ActiveWindow.FreezePanes = True
End If
目前還不是很清楚你要做什么以及它是如何工作的。
你的代碼
如果您的想法是過濾掉用管道標記的行,則需要列的標題,如果列標題位於第1行,我的修改版本將如下所示:
Sub MarkForFilterFromHereBelow()
CURrow = ActiveCell.Row
LASTrow = ActiveCell.SpecialCells(xlLastCell).Row
LASTcol = ActiveCell.SpecialCells(xlLastCell).Column
If LASTrow > CURrow Then
Columns("A").Insert Shift:=xlToRight
Range(Cells(CURrow + 1, 1), Cells(LASTrow, 1)).Value = "|"
Columns(1).HorizontalAlignment = xlCenter
Cells(1, 1).Value = "FilterColumn" 'This is the column title
Range(Cells(1, 1), Cells(LASTrow, LASTcol + 1)).AutoFilter
'Here you can add a row to filter the rows marked with |?
Rows(2).Select
ActiveWindow.FreezePanes = True
End If
End Sub
但顯然我有太多的ifs來回答你的問題。 :-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.