gpt4 book ai didi

excel - 添加通配符搜索和其他条件

转载 作者:行者123 更新时间:2023-12-04 22:16:44 24 4
gpt4 key购买 nike

我正在尝试向搜索框添加通配符,但即使搜索框中没有任何内容,执行也会继续,如果框为空,我应该如何停止搜索?
谢谢

For Each Cognome In intervallo
If Cognome Like Sheets(1).Ricerca = "" Then
Exit For
ElseIf Cognome Like Sheets(1).Ricerca & "*" Then
Sheets(4).Range(Cognome, Cognome.Offset(0, 8)).Copy
Sheets(1).Range("A" & (Rows.Count)).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End If

最佳答案

在进入循环之前检查搜索词

Sub MyMacro()

Dim s As String, r As Long
Dim Cognome As Range, intervallo As Range

Set intervallo = Sheets(4).Range("A1:A100")
r = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
s = Trim(Sheets(1).Ricerca)

If Len(s) = 0 Then
MsgBox "Search box empty", vbExclamation
Else
For Each Cognome In intervallo
If Cognome.Value2 Like s & "*" Then
r = r + 1
Cognome.Resize(1, 8).Copy
Sheets(1).Range("A" & r).PasteSpecial xlPasteValues
End If
Next
End If
End Sub

关于excel - 添加通配符搜索和其他条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68320391/

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