gpt4 book ai didi

Excel-VBA : Get Value of a Visible Cell in a Table after applying Filter?

转载 作者:行者123 更新时间:2023-12-03 00:18:59 25 4
gpt4 key购买 nike

我正在尝试以简单的方式获取表格(也称为)ListObject 中的第一个可见单元格。

到目前为止的代码:

Sub StatusFilter()

Set WB = ThisWorkbook
Set iFace = WB.Sheets("Interface")
Set DataS = WB.Sheets("Data")

iCriteria = iFace.Range("Q22").Value
DataS.Activate
ActiveSheet.ListObjects("Data").Range.AutoFilter 14, iCriteria

ActiveSheet.ListObjects("Data").DataBodyRange.Select

With Columns("A")
.Find(what:="*", after:=.Cells(1, 1), LookIn:=xlValues).Activate
End With
DValue = ActiveCell.Value

If DValue = "" Then
MsgBox "Lucky! No Tickets are in this Criteria!!", vbInformation, "Technology Issue Tracker"
Exit Sub
End If

End Sub

最佳答案

使用您的代码,您应该初始化变量。

这样的东西应该可以工作(推论 - 这是未经测试的)

Sub StatusFilter()

Dim WB As Workbook: Set WB = ThisWorkbook
Dim iFace As Worksheet: Set iFace = WB.Sheets("Interface")
Dim DataS As Worksheet: Set DataS = WB.Sheets("Data")

Dim iCriteria As String: iCriteria = iFace.Range("Q22")
Dim DValue As String

With DataS.ListObjects("Data").Range
.AutoFilter 14, iCriteria
DValue = Index(.SpecialCells(xlCellTypeVisible), 1).Value
End With

If DValue = "" Then
MsgBox "Lucky! No Tickets are in this Criteria!!", vbInformation, "Technology Issue Tracker"
Exit Sub
End If

End Sub

关于Excel-VBA : Get Value of a Visible Cell in a Table after applying Filter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53134230/

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