gpt4 book ai didi

vba - 如何使用Excel VBA选择过滤后的数据而不包含列名?

转载 作者:行者123 更新时间:2023-12-01 22:19:31 27 4
gpt4 key购买 nike

下面是我想出的代码,但是问题出在第 3 行,其中过滤后的数据不一定从第 2 行开始。如果满足条件的第一个数据点位于第 150 行,那么它将返回错误:

Error

Total_Rows_Compiled = Worksheets("Compiled").Range("A" & Rows.Count).End(xlUp).Row
Worksheets("Compiled").Range("$A$1:$G$52818").AutoFilter Field:=1, Criteria1:=Worksheets("Sheet1").Cells(l, 1)
Worksheets("Compiled").Range("A2:G" & Total_Rows_Compiled).SpecialCells(xlCellTypeVisible).Select

最佳答案

您的代码似乎没有任何重大错误。考虑到这一点,以下是我发现相当无错误的方法组合。

with Worksheets("Compiled")
.activate
if .autofiltermode then .autofiltermode = false
Total_Rows_Compiled = .Range("A" & .Rows.Count).End(xlUp).Row
with .range("A1:G" & Total_Rows_Compiled)
.AutoFilter Field:=1, Criteria1:=Worksheets("Sheet1").Cells(l, 1)
with .resize(.rows.count-1, .columns.count).offset(1, 0)
if cbool(application.subtotal(103, .cells)) then
.SpecialCells(xlCellTypeVisible).Select
end if
end with
end with
end with

关于vba - 如何使用Excel VBA选择过滤后的数据而不包含列名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48939559/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com