Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
VBA如何在不显示后继续显示数组元素_Vba_Loops_For Loop_Iteration_Skip - Fatal编程技术网

VBA如何在不显示后继续显示数组元素

VBA如何在不显示后继续显示数组元素,vba,loops,for-loop,iteration,skip,Vba,Loops,For Loop,Iteration,Skip,我的excel宏有问题。 我想在excel文件中找到名称,并将其复制到不同的单元格中。 我创建了一个包含名称和FOR循环的数组来检查它。在那个for循环中,我从数组中查找名称。问题是:如果单元格中的数组中没有名称,则程序停止并给我MsgBox“no name:”+persons(j),然后在此程序停止之后。是否可以向用户提供“文件中没有该名称”的信息并跳过此迭代 非常感谢你的帮助 这是我的密码: Sub wyszukaj() Dim persons As Variant pers

我的excel宏有问题。 我想在excel文件中找到名称,并将其复制到不同的单元格中。 我创建了一个包含名称和FOR循环的数组来检查它。在那个for循环中,我从数组中查找名称。问题是:如果单元格中的数组中没有名称,则程序停止并给我MsgBox“no name:”+persons(j),然后在此程序停止之后。是否可以向用户提供“文件中没有该名称”的信息并跳过此迭代

非常感谢你的帮助

这是我的密码:

Sub wyszukaj()
    Dim persons As Variant
    persons = Array("Dawid", "Mikael", "John", "Alice", "Katerine")
    Dim rowNum As Long
    Dim foundRowNum As String
    Dim findName As String
    Dim j As Long

    For j = LBound(persons) To UBound(persons)
        Dim found As Range
        Dim curSheet As Worksheet
        Dim LastCell As Range
        Dim FirstAddr As String
        With Range("A:A")
            Set LastCell = .Cells(.Cells.Count)
        End With
        Dim nothingInCell As Object
        Set nothingInCell = Nothing

        Set FoundCell = Range("A:A").Find(persons(j), After:=LastCell)

        If FoundCell Is Nothing Then
            MsgBox ("No name: " + persons(j))
        End If

        Debug.Print FoundCell.Value

        If Not FoundCell <> persons(j) Then
            FirstAddr = FoundCell.Address
        End If
        Next j

        Dim counter As Integer
        Dim i As Integer
        counter = 0

        Do Until FoundCell Is Nothing
            counter = counter + 1
            Set FoundCell = Range("A:A").FindNext(After:=FoundCell)
            If FoundCell.Address = FirstAddr Then
                Exit Do
            End If
        Loop

        foundRowNum = FoundCell.Address
        rowNum = Range(foundRowNum).Row

        For i = rowNum To rowNum + counter - 1
            Cells(i, 1).Copy Cells(i, 8)
            Cells(i, 2).Copy Cells(i, 9)
        Next i
End Sub
Sub-wyszukaj()
作为变体的弱智者
persons=数组(“Dawid”、“Mikael”、“John”、“Alice”、“Katerine”)
Dim rowNum尽可能长
Dim foundRowNum作为字符串
Dim findName As String
Dim j尽可能长
对于j=LBound(人)至UBound(人)
作为射程找到的昏暗
将光标变暗为工作表
将最后一个单元格设置为范围
Dim FirstAddr作为字符串
带范围(“A:A”)
设置LastCell=.Cells(.Cells.Count)
以
作为对象的细胞
设置NothingCell=Nothing
设置FoundCell=Range(“A:A”)。查找(persons(j),After:=LastCell)
如果FoundCell什么都不是
MsgBox(“姓名:+人(j))
如果结束
Debug.Print FoundCell.Value
如果没有找到(j)个人,则
FirstAddr=FoundCell.Address
如果结束
下一个j
作为整数的Dim计数器
作为整数的Dim i
计数器=0
直到FoundCell一文不值
计数器=计数器+1
设置FoundCell=Range(“A:A”)。FindNext(之后:=FoundCell)
如果FoundCell.Address=FirstAddr,则
退出Do
如果结束
环
foundRowNum=FoundCell.Address
rowNum=范围(foundRowNum).Row
对于i=rowNum到rowNum+计数器-1
单元格(i,1)。复制单元格(i,8)
单元格(i,2)。复制单元格(i,9)
接下来我
端接头

您需要使用以下结构:

If FoundCell Is Nothing Then 
    'nothing found
Else
    'something found
End If
依赖于
FoundCell
的所有零件都需要位于上面的
Else
零件中

Sub wyszukaj()
    Dim persons As Variant
    persons = Array("Dawid", "Mikael", "John", "Alice", "Katerine")
    Dim rowNum As Long
    Dim foundRowNum As String
    Dim findName As String
    Dim j As Long

    For j = LBound(persons) To UBound(persons)
        Dim found As Range
        Dim curSheet As Worksheet
        Dim LastCell As Range
        Dim FirstAddr As String
        With Range("A:A")
            Set LastCell = .Cells(.Cells.Count)
        End With
        Dim nothingInCell As Object
        Set nothingInCell = Nothing

        Set FoundCell = Range("A:A").Find(persons(j), After:=LastCell)

        If FoundCell Is Nothing Then
            'nothing found
            MsgBox ("No name: " + persons(j))
        Else
            'something found
            Debug.Print FoundCell.Value
    
            If Not FoundCell <> persons(j) Then
                FirstAddr = FoundCell.Address
            End If
        End If
    Next j

    Dim counter As Long
    Dim i As Long
    counter = 0

    Do Until FoundCell Is Nothing
        counter = counter + 1
        Set FoundCell = Range("A:A").FindNext(After:=FoundCell)
        If FoundCell.Address = FirstAddr Then
            Exit Do
        End If
    Loop

    foundRowNum = FoundCell.Address
    rowNum = Range(foundRowNum).Row

    For i = rowNum To rowNum + counter - 1
        Cells(i, 1).Copy Cells(i, 8)
        Cells(i, 2).Copy Cells(i, 9)
    Next i
End Sub
Sub-wyszukaj()
作为变体的弱智者
persons=数组(“Dawid”、“Mikael”、“John”、“Alice”、“Katerine”)
Dim rowNum尽可能长
Dim foundRowNum作为字符串
Dim findName As String
Dim j尽可能长
对于j=LBound(人)至UBound(人)
作为射程找到的昏暗
将光标变暗为工作表
将最后一个单元格设置为范围
Dim FirstAddr作为字符串
带范围(“A:A”)
设置LastCell=.Cells(.Cells.Count)
以
作为对象的细胞
设置NothingCell=Nothing
设置FoundCell=Range(“A:A”)。查找(persons(j),After:=LastCell)
如果FoundCell什么都不是
“什么也没找到
MsgBox(“姓名:+人(j))
其他的
“找到什么了
Debug.Print FoundCell.Value
如果没有找到(j)个人,则
FirstAddr=FoundCell.Address
如果结束
如果结束
下一个j
昏暗的柜台一样长
我想我会坚持多久
计数器=0
直到FoundCell一文不值
计数器=计数器+1
设置FoundCell=Range(“A:A”)。FindNext(之后:=FoundCell)
如果FoundCell.Address=FirstAddr,则
退出Do
如果结束
环
foundRowNum=FoundCell.Address
rowNum=范围(foundRowNum).Row
对于i=rowNum到rowNum+计数器-1
单元格(i,1)。复制单元格(i,8)
单元格(i,2)。复制单元格(i,9)
接下来我
端接头

您需要使用以下结构:

If FoundCell Is Nothing Then 
    'nothing found
Else
    'something found
End If
依赖于
FoundCell
的所有零件都需要位于上面的
Else
零件中

Sub wyszukaj()
    Dim persons As Variant
    persons = Array("Dawid", "Mikael", "John", "Alice", "Katerine")
    Dim rowNum As Long
    Dim foundRowNum As String
    Dim findName As String
    Dim j As Long

    For j = LBound(persons) To UBound(persons)
        Dim found As Range
        Dim curSheet As Worksheet
        Dim LastCell As Range
        Dim FirstAddr As String
        With Range("A:A")
            Set LastCell = .Cells(.Cells.Count)
        End With
        Dim nothingInCell As Object
        Set nothingInCell = Nothing

        Set FoundCell = Range("A:A").Find(persons(j), After:=LastCell)

        If FoundCell Is Nothing Then
            'nothing found
            MsgBox ("No name: " + persons(j))
        Else
            'something found
            Debug.Print FoundCell.Value
    
            If Not FoundCell <> persons(j) Then
                FirstAddr = FoundCell.Address
            End If
        End If
    Next j

    Dim counter As Long
    Dim i As Long
    counter = 0

    Do Until FoundCell Is Nothing
        counter = counter + 1
        Set FoundCell = Range("A:A").FindNext(After:=FoundCell)
        If FoundCell.Address = FirstAddr Then
            Exit Do
        End If
    Loop

    foundRowNum = FoundCell.Address
    rowNum = Range(foundRowNum).Row

    For i = rowNum To rowNum + counter - 1
        Cells(i, 1).Copy Cells(i, 8)
        Cells(i, 2).Copy Cells(i, 9)
    Next i
End Sub
Sub-wyszukaj()
作为变体的弱智者
persons=数组(“Dawid”、“Mikael”、“John”、“Alice”、“Katerine”)
Dim rowNum尽可能长
Dim foundRowNum作为字符串
Dim findName As String
Dim j尽可能长
对于j=LBound(人)至UBound(人)
作为射程找到的昏暗
将光标变暗为工作表
将最后一个单元格设置为范围
Dim FirstAddr作为字符串
带范围(“A:A”)
设置LastCell=.Cells(.Cells.Count)
以
作为对象的细胞
设置NothingCell=Nothing
设置FoundCell=Range(“A:A”)。查找(persons(j),After:=LastCell)
如果FoundCell什么都不是
“什么也没找到
MsgBox(“姓名:+人(j))
其他的
“找到什么了
Debug.Print FoundCell.Value
如果没有找到(j)个人,则
FirstAddr=FoundCell.Address
如果结束
如果结束
下一个j
昏暗的柜台一样长
我想我会坚持多久
计数器=0
直到FoundCell一文不值
计数器=计数器+1
设置FoundCell=Range(“A:A”)。FindNext(之后:=FoundCell)
如果FoundCell.Address=FirstAddr,则
退出Do
如果结束
环
foundRowNum=FoundCell.Address
rowNum=范围(foundRowNum).Row
对于i=rowNum到rowNum+计数器-1
单元格(i,1)。复制单元格(i,8)
单元格(i,2)。复制单元格(i,9)
接下来我
端接头

OMG太简单了。。。谢谢!天哪,这么简单。。。谢谢!