gpt4 book ai didi

excel - Excel错误1004 'No cells were found '

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

因此,这引发了错误1004,未找到任何单元格,他们以这种方式处理了似乎无法正常工作的错误。无论如何,我可以避免该错误吗?谢谢!

Private Sub ComboBox1_Enter()

On Error Resume Next
Dim rrange As Range
Dim VisibleRange As Range
Dim rcell As Object

Set rrange = Sheets("Project details").Range("A2:A150")

Dim byCSMCoprId As String 'corp id goes into criteria for autofilter.
byCSMCoprId = TextBox1.Text
On Error GoTo Error_Handler
With Sheets("Project details").Range("A1:M1")
.autofilter field:=2, Criteria1:=byCSMCoprId
.autofilter field:=7, Criteria1:=""
End With
Set VisibleRange = rrange.SpecialCells(xlCellTypeVisible)
For Each rcell In VisibleRange
ComboBox1.AddItem rcell
Next
Error_Handler:
If Err.Number = 1004 And Err.Description = "No cells were found." Then GoTo Message:

Message:
MsgBox "No cells were found"
End Sub

最佳答案

我会发现类似这样的内容更容易理解:

Private Sub ComboBox1_Enter()

Dim rrange As Range
Dim VisibleRange As Range
Dim rcell As Object

Set rrange = Sheets("Project details").Range("A2:A150")

Dim byCSMCoprId As String 'corp id goes into criteria for autofilter.
byCSMCoprId = TextBox1.Text

With Sheets("Project details").Range("A1:M1")
.autofilter field:=2, Criteria1:=byCSMCoprId
.autofilter field:=7, Criteria1:=""
End With

On Error Resume Next
Set VisibleRange = rrange.SpecialCells(xlCellTypeVisible)
On Error Goto 0

If Not VisibleRange Is Nothing Then
For Each rcell In VisibleRange
ComboBox1.AddItem rcell
Next
Else
Msgbox "No cells found"
End if
End Sub

关于excel - Excel错误1004 'No cells were found ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35872579/

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