Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA-重新初始化范围_Vba_Excel - Fatal编程技术网

Excel VBA-重新初始化范围

Excel VBA-重新初始化范围,vba,excel,Vba,Excel,在宏中,我在文件的每个工作表中应用相同的处理 我想确定哪个列包含特定的文本,每个工作表中的文本可能不同 代码如下: For Each Cell_version In Ws.Range("1:1") If Ws.Range(convertir(Cell_version.Column) & "1") = "ICI" Then Column_version = convertir(Cell_version.Column) Trouve_col = Tru

在宏中,我在文件的每个工作表中应用相同的处理

我想确定哪个列包含特定的文本,每个工作表中的文本可能不同

代码如下:

For Each Cell_version In Ws.Range("1:1")
    If Ws.Range(convertir(Cell_version.Column) & "1") = "ICI" Then
        Column_version = convertir(Cell_version.Column)
        Trouve_col = True
        MsgBox (Column_version)
    End If
If Trouve_col = True Then Exit For
Next Cell_version

在第一个工作表中,所有内容都正常工作,并在相应的列
列D
中找到文本。在第二个工作表中,如果该列位于D列之后,它也会起作用。但是,如果是
列A、B或C
,则不会返回包含所需文本的列。如何解决此问题?

我的VBA有些生疏,但我始终更喜欢使用
Find
命令,因为它是搜索工作表的最快方法,可能如下所示:

Sheets("YourSheet").Select

Cells(1, 1).Select

Set found = Cells.Find(What:="ICI", After:=ActiveCell, LookIn:=xlValues, _
    LookAt:=xlColumn, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)

If Not found Is Nothing Then
    found.Activate      
    MsgBox(Selection.Row)
End If